typescript - 打字稿抱怨解构类型
问题描述
我有以下代码:
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
推荐阅读
- python - CoinOR cbc 不接受期权 (pyomo)
- c++ - 降低在 C++ 中比较单个字符串中的两个字符的时间复杂度
- python - Python opencv人脸识别视频不流畅
- amazon-web-services - 带有 WebSocket 的 Amazon AWS 网关 API
- swift - 呈现 UIViewControllers 的常用方法
- go - Golong (gorm) - 如何使用 json 创建新记录
- android - 即使应用程序关闭或未使用,如何在后台跟踪特定时间间隔的位置 targetSdkVersion 30
- android - 如何在jetpack compose中预览对话框?
- ant - 根据文件扩展名修改文件列表
- parameter-passing - databricks sql分析中的参数