Hacker News new | ask | show | jobs
by DCoder 3899 days ago
> Every JS code is a valid TS, since TS is a superset of JS.

There are still cases where you'll need to sprinkle <any>. For example:

    var state = { foo: 1 };
    if(something) {
      state.bar = 2;
    }
is valid JS, but the TS compiler will complain that `state` does not have a member named `bar`.
1 comments

The TS compiler will complain but still generate working JS code, so you don't lose anything.
But the compiler's output will be polluted with these false positives, making it harder to see actual errors. (Also, there's a compiler flag to prevent codegen on error, which comes in handy sometimes.)