import { ObjectType, ID, Int, Field } from 'type-graphql';
@ObjectType()
export default class Address {
@Field(type => ID)
id: String;
@Field()
type: string;
@Field()
title: string;
@Field()
location: string;
}信息: ts-node-dev ver.1.0.0 (使用ts-node版本9.1.1,typescript版本4.0.5)
当使用这个命令ts-node-dev --respawn server.shop.ts启动应用程序时,我得到了以下错误。(无法从TypeScript反射系统推断GraphQL类型。您需要为“Address”类的“id”提供显式类型。)
发布于 2021-03-18 14:02:06
定义一个接口并使用@InterfaceType()装饰器对其进行装饰
@InterfaceType()
abstract class IAddress {
@Field(type => ID)
id: string;
@Field()
type: string;
@Field()
title: string;
@Field()
location: string;
}然后在Address类中实现它,如下所示
@ObjectType({ implements: IAddress })
export default class Address implements IAddress {
id: string;
type: string;
title: string;
location: string
}阅读有关定义接口here的更多信息
发布于 2021-11-17 04:45:03
添加
"experimentalDecorators": true,
"emitDecoratorMetadata": true,在你的tsconfig.json中
https://stackoverflow.com/questions/66685493
复制相似问题