简体   繁体   中英

How to use typescript typing for a legacy project in vscode

Currently I have a project with structure

...
└───folder1
│   │   file011.js
│   │   file012.js
│   └───...
└───folder2
│   │   file021.js
│   └───file022.js
│
└─── files...

I tried to include a type.d.ts to the root, then tried putting it in a typings folder but none worked.

How do I enable typing for my case ? There is no folder with name src

With TypeScript 2.3 you can specify the checkJS option to type check JS files.

Documentation: https://github.com/Microsoft/TypeScript/wiki/Type-Checking-JavaScript-Files

It won't work as long as your files are still named "*.js". Try renaming a file to ".ts", then the typescript compiler can do it's magic.

You also have to create a tsconfig.json to configure the typescript compiler.

The settings really depend on the type of project you are using. If you don't use a module system like requirejs, you need to get typings for global modules.

EDIT: Removed reference to Visual Studio project settings as this question is about vscode

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM