Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vscode intellisense node.js works for .js files - not .ts files

Unable to get intellisense to work for .ts files.

test.js

var http = require('http');
http.[intellisense available]

test.ts

var http = require('http');
http.[no suggestions]

Does not appear to be reading index.d.ts

Here is tsconfig.json:

{
  "compileOnSave": true,
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "sourceMap": true,
    "watch": true
  }
}

Any suggestions. Really want to use typescript, but need the hints while learning node. Prefer not to use javascript.

Thanks.

like image 705
Jim Rand Avatar asked Mar 08 '23 05:03

Jim Rand


1 Answers

Learning curve.

For a .js file:

var http = require('http');

for a .ts file:

import http = require('http');

The transpiler will write out: var http = ...

The "import" instead of "var" gets intellisense to work. Right clicking for "go to definition" works.

Problem solved.

like image 132
Jim Rand Avatar answered Mar 11 '23 13:03

Jim Rand