Quantcast
Channel: Active questions tagged visual-studio-code - Stack Overflow
Viewing all articles
Browse latest Browse all 97327

Is it possible to type-check only imported libraries (Typescript, VSCode)?

$
0
0

Basic question: Is it possible to type-check only imports?

I do want to know

  • TS: property 'id' does not exist on type 'Stripe.customer' (for example)
  • but not on my own objects, like property 'prop1' does not exist on type '{}'

Background

  • I'm working on a Javascript project, and I'd like to use Typescript for added intellisense with imported libraries, while otherwise writing in JS, so I've changed my .js file to .ts during development. († see bottom)

  • In the Javascript project, lots of objects are initialized as let x = {} and then properties are later added as x.prop1 = value1.

  • TSLint then warns me, property 'prop1' does not exist on type 'x'.

I would like to get this warning only on imports.

  • For instance, if I import * as stripe from 'stripe', then it's helpful to get the warning property 'id' doest not exist on type 'customer'.

  • Following this thread, property does not exists on type '{}' , I can achieve this manually on a per-object basis by converting x.prop1 to x['prop1'].

  • I've also experimented with inline comments to disable various TSLint rules, but the warnings are coming from the Typescript language features in VSCode, not TSLint.

However, to restate the question more precisely: Is there directive or config option that would allow me to add properties to objects defined in my own code without warning, while still warning/type-checking imported libraries?

† If there's a alternative, less janky way to get intellisense on imported libraries in Javascript, I'm all ears!


Viewing all articles
Browse latest Browse all 97327

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>