Why not just make that "let x" a "const x" which JS already allows?
Why not just make that "let x" a "const x" which JS already allows?
Here's a concrete example. The `printSwitch` call fails because `state: 'OFF'` is inferred as having a `string` value. In TS 3.4, you could write `'OFF' as const` and it would work.
https://www.typescriptlang.org/play/index.html#src=interface...
TS is already pretty good about this, e.g. if you write `const s: Switch = {`, then it'll have enough context clues to know that `'OFF'` should have type `'OFF'`, but the new `as const` syntax is a way to explicitly say that the type shouldn't be expanded to `string`.
Why use "let" along with "as const" instead of mere "const x = 'hello'" for that?
This is different to the widening of value types within objects, which is a tradeoff made towards unsoundness with the belief that it would otherwise make interoperability with existing js too difficult, for which `as const` now serves as a way to explicitly opt into sounder behavior.