1

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

bigopon
  • 1,924
  • 2
  • 14
  • 23
  • 1
    Not sure if this might help, but TypeScript 2.3 has an option to type check JS files with the `checkJS` option: https://github.com/Microsoft/TypeScript/wiki/Type-Checking-JavaScript-Files – Saravana May 09 '17 at 13:14
  • Yup that's the answer, enabling checkTs makes vscode pickup the file. Thanks :) If you can, create an answer for it and i'll mark accepted. – bigopon May 10 '17 at 00:21

2 Answers2

3

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

Saravana
  • 37,852
  • 18
  • 100
  • 108
2

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

mode777
  • 3,037
  • 2
  • 23
  • 34
  • So you are suggesting me to change all files to `.ts` for intellisense ? It's a bit of problem as the build tool isn't that easy to pick up the change – bigopon May 09 '17 at 12:42
  • You will only get the benefits of typescript definition intellisense inside typescript files. It sounds like, you want to use typescript definitions with your javascript. There is a similar question here http://stackoverflow.com/questions/38370549/how-to-use-typescript-definitions-to-get-intellisense-for-my-own-javascript-serv – mode777 May 09 '17 at 12:51