4 ms·
> 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
by DCoder 11y 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`.
- addicted 11y agoThe TS compiler will complain but still generate working JS code, so you don't lose anything.
- DCoder 11y agoBut 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.)