gpt4 book ai didi

typescript 提示解构类型

转载 作者:行者123 更新时间:2023-12-03 22:26:48 24 4
gpt4 key购买 nike

我有以下代码:

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 值应该是什么类型(或者,更具体地说,它无法推断函数 a 的第一个参数的类型)。只需添加一个明确的类型注释来解决这个问题:

let a = ({System}: { System: string }) => ({

});

string 替换为 System 的实际类型(也许是 typeof systemType ?)

关于 typescript 提示解构类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56368676/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com