|
|
|
|
|
by goto11
1244 days ago
|
|
TypeScript is a superset of JavaScript because any JavaScript program is also a Typescript program but not vice versa. There is no contradiction. > TS as a language is a superset of JS language. TS as a spec is a rough subset of JS spec. This does not make any sense. A spec which fully describes TypeScript including runtime behavior would include the JavaScript spec and therefore be a superset. The TypeScript spec itself is in no way a subset of the JS spec, sine it descries features and syntax which does not exist in vanilla JavaScript. |
|
Code is an instance of Language (and in structural typing land it can be compatible with multiple languages). Language is an instance (implementation) of Spec.
> sine it descries features and syntax which does not exist in vanilla JavaScript
That's exactly why TS spec is a subset. Take example from the article:
Type B is a subset of boolean, meaning there are less objects in the world that satisfy type B.There are less language implementations in the world that satisfy TS spec than JS spec. Every language that satisfies TS spec also satisfies JS spec. TS spec adds more constraints (requirements) to language implementation compared to JS spec, it is more strict, therefore it's a subset.