首页 > 解决方案 > 未知错误,Ben Awad 的“Fullstack React GraphQL TypeScript 教程”

问题描述

我在 Ben Awad 的“Fullstack React GraphQL TypeScript Tutorial”项目中工作。

在 index.ts 中,我的大部分代码都以红色突出显示。
我的代码
当我将鼠标悬停在代码上时出现以下错误

Argument of type '{ schema: GraphQLSchema; context: ({ req, res }: ExpressContext) => 
MyContext; plugins: any[]; }' is not assignable to parameter of type 
'Config<ExpressContext>'.
Type '{ schema: GraphQLSchema; context: ({ req, res }: ExpressContext) => MyContext; 
plugins: any[]; }' is missing the following properties from type 
'Config<ExpressContext>': logger, debug, cache, formatError, and 6 more.ts(2345)

标签: typescript

解决方案


打字稿抱怨,因为它期待 type Config<ExpressContext>,而不是接收 type { schema: GraphQLSchema; context: ({ req, res }: ExpressContext) => MyContext; plugins: any[]; }

假设您不关心缺少的属性,您可以将其转换为Config<ExpressContext>

{ schema: GraphQLSchema; context: ({ req, res }: ExpressContext) => MyContext; plugins: any[]; } as Config<ExpressContext>.


推荐阅读