Far*_*ıcı 5 javascript typescript react-native visual-studio-code
我正在使用 TypeScript 编写 React-Native 项目,到目前为止一切正常,但以下部分引发错误:
export interface Country {
name: string;
cities: Record<string, string>;
}
Run Code Online (Sandbox Code Playgroud)
错误是:
3:13 error 'Record' is not defined no-undef
Run Code Online (Sandbox Code Playgroud)
我的打字稿使用工作区版本而不是 VS Code 的版本。另外,当我 cmd+click 时Record,我可以转到它的定义,它在文件中lib.es5.d.ts:
type Record<K extends keyof any, T> = {
[P in K]: T;
};
Run Code Online (Sandbox Code Playgroud)
所以,Record显然是在node_modules下定义并找到的,但是当我运行linter(@typescript-eslint)时,我无法修复这个错误
我的内容.vscode/settings.json如下所示:
"typescript.tsdk": "node_modules/typescript/lib"
Run Code Online (Sandbox Code Playgroud)
我还没有找到任何解决方案,你能帮忙吗?
打字稿版本:“4.1.4”,
小智 4
该错误可能与配置有关eslint。
'plugin:@typescript-eslint/recommended'通过将 eslint添加到文件extends部分来扩展它eslintrc:
module.exports = {
...
extends: [
...
'plugin:@typescript-eslint/recommended'
]
....
};
Run Code Online (Sandbox Code Playgroud)
并重新加载 vscode 的 TypeScript 服务器。您可以通过Restart TS Server在 vscode 命令面板中输入来完成此操作。
| 归档时间: |
|
| 查看次数: |
511 次 |
| 最近记录: |