首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >无法从TypeScript反射系统推断GraphQL类型。您需要为'Address‘类的'id’提供显式类型

无法从TypeScript反射系统推断GraphQL类型。您需要为'Address‘类的'id’提供显式类型
EN

Stack Overflow用户
提问于 2021-03-18 13:54:39
回答 2查看 1.3K关注 0票数 0
代码语言:javascript
运行
复制
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”提供显式类型。)

EN

回答 2

Stack Overflow用户

发布于 2021-03-18 14:02:06

定义一个接口并使用@InterfaceType()装饰器对其进行装饰

代码语言:javascript
运行
复制
@InterfaceType()
abstract class IAddress {
  @Field(type => ID)
  id: string;

  @Field()
  type: string;

  @Field()
  title: string;

  @Field()
  location: string;
}

然后在Address类中实现它,如下所示

代码语言:javascript
运行
复制
@ObjectType({ implements: IAddress })
export default class Address implements IAddress {
  id: string;
  type: string;
  title: string;
  location: string
}

阅读有关定义接口here的更多信息

票数 0
EN

Stack Overflow用户

发布于 2021-11-17 04:45:03

添加

代码语言:javascript
运行
复制
"experimentalDecorators": true,
"emitDecoratorMetadata": true,

在你的tsconfig.json中

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66685493

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档