2

I am a big fan of vscode. Here's my question, let's say I have a code like this.

const express = require('express')
const app = express()
app.get('/', (req, res) => res.send('Hello World!'))

when I CMD+Click on express(inside require) or on get function, it's taking me to it's typescript definition which is cached in home folder. When I clear the cache, then it's taking me to definitions inside node_modules and the cache is getting build again. Whereas in webstorm, there are no typescript caching, it takes me into node_modules definition. Is it possible to disable typescript definitions and use node_modules definitions ??

as shown in the picture, when I click on <code>express</code> it takes me to tyepscript definition, not the <code>node_modules</code> one.

as shown in the picture, when I click on express it takes me to tyepscript definition, not the node_modules one.

There is a built-in extension called TypeScript and JavaScript Language Features (vscode.typescript-language-features). Disabling that will work ?? I don't know but I am afraid that I lose javascript intellisense.

Anyone know ???

Lokesh Sanapalli
  • 1,012
  • 3
  • 18
  • 39
  • Possible duplicate of [How can I view original javscript library source code in VS Code and not the typescript version?](https://stackoverflow.com/questions/52464407/how-can-i-view-original-javscript-library-source-code-in-vs-code-and-not-the-typ) – Lokesh Sanapalli Nov 17 '18 at 09:46
  • Does this answer your question? [Go to the TypeScript source file instead of the type definition file in VS Code](https://stackoverflow.com/questions/48711065/go-to-the-typescript-source-file-instead-of-the-type-definition-file-in-vs-code) – leonheess May 06 '22 at 22:13

2 Answers2

5

The "cache" is built by a feature called Automatic Type Acquisition. You can disable it by setting VS Code's typescript.disableAutomaticTypeAcquisition setting to true or creating a jsconfig.json file containing {"typeAcquisition": {"enable": false}}. You'll still have to manually remove previously downloaded type declarations in order for links to take you to the implementation JavaScript files. See this answer for some additional related information.

Matt McCutchen
  • 28,856
  • 2
  • 68
  • 75
1

The cache is most probably generated by the mentioned extension. You should not use it to get Typescript Typings, because Typescript's intellisense works out of the box very well.

Do not forget to install typings for each JS package.

npm install @types/express -D

Also in Typescript you should use import, instead of require:

import * as express from 'express' 
Nurbol Alpysbayev
  • 19,522
  • 3
  • 54
  • 89