最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - vscode - replace typescript definitions with node_modules definitions - Stack Overflow

programmeradmin1浏览0评论

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 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 ???

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 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 ???

Share Improve this question edited Nov 16, 2018 at 10:31 Lokesh Sanapalli asked Nov 16, 2018 at 10:14 Lokesh SanapalliLokesh Sanapalli 1,0324 gold badges19 silver badges39 bronze badges 2
  • Possible duplicate of How can I view original javscript library source code in VS Code and not the typescript version? – Lokesh Sanapalli Commented Nov 17, 2018 at 9:46
  • Does this answer your question? Go to the TypeScript source file instead of the type definition file in VS Code – leonheess Commented May 6, 2022 at 22:13
Add a ment  | 

2 Answers 2

Reset to default 6

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.

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' 
发布评论

评论列表(0)

  1. 暂无评论