我有以下代码:
import { GraphQLNonNull, GraphQLString, GraphQLList, GraphQLInt } from 'graphql';
import systemType from './type';
import { resolver } from 'graphql-sequelize';
let a = ({System}) => ({
system: {
type: systemType,
args: {
id: {
description: 'ID of system',
type: new GraphQLNonNull(GraphQLInt)
}
},
resolve: resolver(System, {
after: (result: any[]) => (result && result.length ? result[0] : result)
})
},
systems: {
type: new GraphQLList(systemType),
args: {
names: {
description: 'List option names to retrieve',
type: new GraphQLList(GraphQLString)
},
limit: {
type: GraphQLInt
},
order: {
type: GraphQLString
}
},
resolve: resolver(System, {
before: (findOptions: any, { query }: any) => ({
order: [['name', 'DESC']],
...findOptions
})
})
}
});
export = { a: a };
VSCode抱怨TS7031警告:
Binding element 'System' implicitly has an 'any' type
如何摆脱该警告?
答案 0 :(得分:1)
TypeScript无法从您的代码推断System
值的类型(或更具体地说,它无法推断函数a
的第一个参数的类型)。只需添加一个显式类型注释即可解决此问题:
let a = ({System}: { System: string }) => ({
});
将string
替换为实际的System
类型(也许是typeof systemType
?)