我有以下代码:
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
我怎样才能摆脱那个警告?
TypeScript 无法System
从您的代码中推断出值应该是什么类型(或者,更具体地说,它无法推断出 function 的第一个参数的类型a
)。只需添加一个明确的类型注释来解决这个问题:
let a = ({System}: { System: string }) => ({
});
替换string
为System
(也许typeof systemType
?)的实际类型
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句