Typescript: IntelliSense For Untyped Imports in TypeScript Files

Created on 20 Apr 2017  ·  5Comments  ·  Source: microsoft/TypeScript



From

TypeScript Version: 2.3.1-insider0416

Code

  1. npm install snoowrap
  2. In a ts file:
import * as snoowrap from 'snoowrap'

snoowrap.|
  1. Trigger intellisense at the |

Expected behavior:
The import is of an any type so no type checking is performed on it.

However, if we instead use a js file with the exact same contents, we do get some suggestions:

screen shot 2017-04-19 at 10 56 02 pm

I would also expect these suggestions in TypeScript.

I was actually surprised that TypeScript picked up this IntelliSense for an untyped module in the first place. When was this feature added?

Actual behavior:
No suggestions are shown. This is consistent with the intellisense for other any types

VS Code Tracked Working as Intended

Most helpful comment

dts-gen sounds great in theory, but doesn't seem to work well sometimes including the sample package here.

I would say these bugs that should be fixed in dts-gen

I wonder what TypeScript is doing different when processing .

nothing, it is just that there are many .js files out there, and including them all first results in little value, as the compiler does not usually get much out of them, and result in high resource utilization, in terms of memory and CPU.

It just feels really funny when the intellisense works in untyped JS but not in typed territory!

For the .js file it is a best effort attempt. it may work for this specific library, but no guarantees on other ones. As i said, you are better off adding a .d.ts.

All 5 comments

Hello awesome TypeScript maintainer.
Any thoughts on this? Maybe a comment whether it's a bug or by design / expected for some reason?

Thanks a lot.

The reason it works in .js file is because of the node_module\snoowrap\dist\snoowrap.js into your compilation by default.

I would not recommend doing so in a .ts project. you are better off runnign dts-gen on it, getting a d.ts and using that instead.

dts-gen sounds great in theory, but doesn't seem to work well sometimes including the sample package here. I wonder what TypeScript is doing different when processing .JS files in VS Code that I can apply to my tsconfig.json or something to get the same behavior. It just feels really funny when the intellisense works in untyped JS but not in typed territory!

A few more things:

  • If there's a tsconfig.json that has allowJs set to true, and includes the .js file, it gets treated (correctly) as a TS file, but it means it loses intellisense
  • When the file is treated as JavaScript file, we get hints from JSDoc, but when it's treated as TypeScript, we lose the JSDoc comments (makes sense in TypeScript in general, not 100% useful when importing a JS module though).

dts-gen sounds great in theory, but doesn't seem to work well sometimes including the sample package here.

I would say these bugs that should be fixed in dts-gen

I wonder what TypeScript is doing different when processing .

nothing, it is just that there are many .js files out there, and including them all first results in little value, as the compiler does not usually get much out of them, and result in high resource utilization, in terms of memory and CPU.

It just feels really funny when the intellisense works in untyped JS but not in typed territory!

For the .js file it is a best effort attempt. it may work for this specific library, but no guarantees on other ones. As i said, you are better off adding a .d.ts.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

manekinekko picture manekinekko  ·  3Comments

siddjain picture siddjain  ·  3Comments

fwanicka picture fwanicka  ·  3Comments

kyasbal-1994 picture kyasbal-1994  ·  3Comments

Zlatkovsky picture Zlatkovsky  ·  3Comments