【问题标题】:How can I specify the return type of a NestJs controller with a Sequelize-Typescript model definition?如何使用 Sequelize-Typescript 模型定义指定 NestJs 控制器的返回类型?
【发布时间】:2020-09-14 20:08:49
【问题描述】:

我试过了:

    @Post()
    async create(@Body() body: CreateStreamDto): Promise<typeof Stream> {
        return { id: '12', connectionUrl: 'stuff' }
    }

但它说:

ype '{ id: string; connectionUrl: string; }' is not assignable to type 'typeof Stream'.
  Object literal may only specify known properties, and 'id' does not exist in type 'typeof Stream'.

【问题讨论】:

  • 什么是Stream?你想在这里返回什么?
  • 这是一个sequelize-typescript 定义的模型:``` @Table export class Stream extends Model { ```

标签: typescript sequelize.js nestjs sequelize-typescript


【解决方案1】:

如果您要返回模型的实例,您应该只需要Promise&lt;Stream&gt;typeof Stream 可能会返回 Object 或类似的东西,这就是您收到上述错误的原因。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-13
    • 2020-08-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多