How to get VScode recognize d.ts files without referencing them directly

前端 未结 2 723
一整个雨季
一整个雨季 2021-02-08 04:44

I have a project created with create-react-app-ts

I also have a set of d.ts files that are generated interfaces from JSON-schema. They define some interface

2条回答
  •  滥情空心
    2021-02-08 04:57

    Based on tsconfig compiler options, you should use option typeRoots. This section of documentation describes the difference between @types, typeRoots and types.

    For your specific case this tsconfig.json file should do the trick:

    {
        "compilerOptions": {
            "typeRoots" : ["./type-definitions-folder"]
        }
    }
    

    If you are also using type definitions from npm you should also add ./node_modules/@types.

    {
        "compilerOptions": {
            "typeRoots" : ["./node_modules/@types", "./type-definitions-folder"]
        }
    }
    

提交回复
热议问题