最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - TypeScript 'Record' is not defined - Stack Overflow

programmeradmin4浏览0评论

I am writing a React-Native project with TypeScript, so far everything works fine but the following part throws an error:

export interface Country {
    name: string;
    cities: Record<string, string>;
}

The error is:

3:13  error  'Record' is not defined  no-undef

My typescript uses the workspace version instead of VS Code's version. Also, when I cmd+click on the Record, I can go to its definition, which is in the file lib.es5.d.ts:

type Record<K extends keyof any, T> = {
    [P in K]: T;
};

So, Record is obviously defined and found under node_modules, however when I run the linter (@typescript-eslint), I can't fix this error

The content of my .vscode/settings.json looks like following:

"typescript.tsdk": "node_modules/typescript/lib"

I have not found any solutions, could you help please?

Typescript version: "4.1.4",

I am writing a React-Native project with TypeScript, so far everything works fine but the following part throws an error:

export interface Country {
    name: string;
    cities: Record<string, string>;
}

The error is:

3:13  error  'Record' is not defined  no-undef

My typescript uses the workspace version instead of VS Code's version. Also, when I cmd+click on the Record, I can go to its definition, which is in the file lib.es5.d.ts:

type Record<K extends keyof any, T> = {
    [P in K]: T;
};

So, Record is obviously defined and found under node_modules, however when I run the linter (@typescript-eslint), I can't fix this error

The content of my .vscode/settings.json looks like following:

"typescript.tsdk": "node_modules/typescript/lib"

I have not found any solutions, could you help please?

Typescript version: "4.1.4",

Share Improve this question asked Mar 17, 2021 at 11:25 Faruk YaziciFaruk Yazici 2,40419 silver badges40 bronze badges 1
  • 1 it might be missing the es5 (or patible) lib in the piler flags (tsconfig.json pilierOptions => lib) – Mr.Manhattan Commented Mar 17, 2021 at 11:54
Add a ment  | 

1 Answer 1

Reset to default 5

This error might be related to the eslint configuration.

make eslint extend 'plugin:@typescript-eslint/remended' by adding it to extends section of eslintrc file:

module.exports = {
    ...
    extends: [
        ...
        'plugin:@typescript-eslint/remended'
    ]
    ....
};

and reload vscode's TypeScript Server. you can do so by typing Restart TS Server in vscode mand palette.

发布评论

评论列表(0)

  1. 暂无评论