4 ms·
> not all npm packages are typescript All Javascript is Typescript isn't it?
by frenchman99 4y ago
> not all npm packages are typescript
All Javascript is Typescript isn't it?
- georgyo 4y agoAll typescript is JavaScript, not all JavaScript is typescript.
- geysersam 4y agoNope. From the docs: > Typescript is a strict syntactical superset of JavaScript Typescript contains more than JS. But all JS is valid Typescript.
- lioeters 4y agoI think you mean the other way around. TypeScript is a superset of JavaScript. Most TS is not valid JS, but all JS is valid TS.
- deckard1 4y agoLooking at it in terms of sets is not really useful because the utility of TS is to exclude invalid behavior. JS allows many things which are not permissible in TS. Semantically, not syntactically. And TS can't infer a number of things such as higher-order functions. So you either have external definitions for those libraries, give up and type it "any" (and taint your entire code base), or have errors which means you can't use the JS library with your TS code base. Or to put it another way, JS is only a subset of TS in as far as you're willing to forgo the benefits of TS.