|
|
|
|
|
by hbrn
1244 days ago
|
|
This is how you should think about it: Spec > Language > Code. 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 = true extends boolean ? 1 : 0; // 1
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. |
|
(Although in reality the Typescript implementation is a preprocessor, intended to use together with a regular JavaScript engine.)