У меня есть следующий код:
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?)