Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> not all npm packages are typescript

All Javascript is Typescript isn't it?



All typescript is JavaScript, not all JavaScript is typescript.


I 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.


Looking 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.


Nope.

From the docs:

> Typescript is a strict syntactical superset of JavaScript

Typescript contains more than JS. But all JS is valid Typescript.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: