typescript - 未知错误,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)
解决方案
打字稿抱怨,因为它期待 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>
.
推荐阅读
- react-redux - ReactJS 在 componentdidupdate 中比较两个对象
- python - OOPS 组成和 IS-A 关系
- reactjs - 如何在 Chartjs 中为未知数量的数据集生成颜色
- c - 如何在 Linux 中获得正确的堆起始地址?
- python - OSError:无法打开资源
- scala - Scala:从数据框中选择列时使用 spark sql 函数
- puppeteer - 无头文件下载:false,但未保存
- javascript - 上传捕获图像并将其存储在文件夹中,使用用户 ID 将其文件名更改为唯一
- python - Python 总是返回 False
- python - 使用 Arduino 使用 Tkinter 时打开/关闭 LED