|
|
|
|
|
by hbrn
1243 days ago
|
|
Kind of. The language gets confusing because we use subset and superset next to each other, but we put different meaning on them. {foo: number, bar: string} as type is a subset of both {foo: number} and {bar: string}. It requires it's members to have both properties. You can construct this type using intersection: type Foo = {foo: number}
type Bar = {bar: string}
type FooBar = foo & bar
{foo: 1, bar: 'hello'} as object is a superset of {foo: 1} and {bar: 'hello'}. It contains both properties. We can construct this object using union (I use pipe instead of spread to illustrate the idea): let foo = {foo: 1}
let bar = {bar: 'hello'}
let foobar = foo | bar
When I'm saying TS is a superset of JS, I mean it in the object sense. It has all the properties of JS, and some more. All JS programs are also TS programs, but not vice versa. There's more JS programs in the world than TS programs.When I'm saying TS spec is a subset of JS spec, I mean it in a type sense. Language is an instance of a spec. TS spec has all of the requirements of JS spec, and some more. All TS implementations (languages) will contain JS implementations, but not vice versa. There's more JS implementations in the world, than TS implementations (assuming you can build TS as compiler/interpreter instead of transpiler). |
|
I think you are confusing terminology, because those two statements are contradictory.