Nestjs使用示例抛出TS2322错误

时间:2018-11-14 20:26:07

标签: node.js typescript nestjs

我是嵌套的新手,我遇到了一个错误,对我来说这确实不是可解码的。我尝试遵循nest example,但没有运气。

output_data[0][0][0][5:85]

app.module.ts

 [tsl] ERROR in /Users/user/Documents/development/sprinta/src/server/app.module.ts(12,5)
[0]       TS2322: Type '(DynamicModule | typeof ProjectModule)[]' is not assignable to type 'Type<any> | DynamicModule | Promise<DynamicModule> | ForwardReference<any>'.
[0]   Type '(DynamicModule | typeof ProjectModule)[]' is not assignable to type 'ForwardReference<any>'.
[0]     Property 'forwardRef' is missing in type '(DynamicModule | typeof ProjectModule)[]'.

project.module.ts

import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AngularUniversalModule } from './modules/angular-universal/angular-universal.module';
import { JiraService } from './services/jira.service'
// modules
import { ProjectModule } from './resources/local/projects/project.module'
// sync
import {ProjectsSync} from './sync/projects.sync'

@Module({
  imports: [
    [TypeOrmModule.forRoot(), ProjectModule],
    AngularUniversalModule.forRoot(),
  ],
  controllers: [],
  providers:[JiraService, ProjectsSync],
})
export class ApplicationModule {}

project.service.ts

import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ProjectService } from './project.service';
import { ProjectController } from './project.controller';
import { Project } from './project.entity';

@Module({
  imports: [TypeOrmModule.forFeature([Project])],
  providers: [ProjectService],
  controllers: [ProjectController],
})
export class ProjectModule {}

project.entity.ts

import { Injectable, Inject } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Project } from './project.entity';

@Injectable()
export class ProjectService {
  constructor(
    @InjectRepository(Project)
    private readonly projectRepository: Repository<Project>,
  ) {}

  async findAll(): Promise<Project[]> {
    return await this.projectRepository.find();
  }
}

project.controller.ts

import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';

@Entity()
export class Project {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ length: 500 })
  name: string;
}

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

您在TypeOrmModule.forRoot()ProjectModule周围有一个额外的嵌套数组。 @Module调用应显示为:

@Module({
  imports: [
    TypeOrmModule.forRoot(), ProjectModule,
    AngularUniversalModule.forRoot(),
  ],
  controllers: [],
  providers:[JiraService, ProjectsSync],
})