我有一个模型Location
,关系是和它自己。
class Location extends Model<Location> {
...
@BelongsTo(() => Location, "countryId")
public country?: Location;
@BelongsTo(() => Location, "stateId")
public state?: Location;
@HasMany(() => Location, "countryId")
public states?: Location[];
@HasMany(() => Location, "stateId")
public regions?: Location[];
@HasMany(() => Location, "regionId")
public places?: Location[];
...
}
所以基本上 counties
有很多 states
有很多 region
等等。我想将其实现为 GraphQLType
.
我尝试了什么:
const LocationType = new GraphQLObjectType({
name: "LocationType",
fields: () => ({
...
states: {type: new GraphQLList(LocationType)},
...
}),
});
我得到的错误
'LocationType' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
最佳答案
您只需将 LocationType
类型指定为 GraphQLObjectType
。
类似这样的:
const LocationType: GraphQLObjectType = new GraphQLObjectType({
name: "LocationType",
fields: () => ({
...
states: {type: new GraphQLList(LocationType)},
...
}),
});
关于typescript - item 没有类型注释,在其自己的初始化程序中直接或间接引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51509990/