» node_modules/typescript/bin/tsc test.ts
test.ts:14:7 - error TS2322: Type '{ id: "primary" | "secondary"; }' is not assignable to type 'X'.
Type '{ id: "primary" | "secondary"; }' is not assignable to type '{ id: "tertiary"; inverted?: false; }'.
Types of property 'id' are incompatible.
Type '"primary" | "secondary"' is not assignable to type '"tertiary"'.
Type '"primary"' is not assignable to type '"tertiary"'.
14 const x: X = {
~
Search Terms:
I did ask here https://stackoverflow.com/questions/54593103/typescript-union-type-with-singleton-types-does-not-compile
Code
Expected behavior:
Compiles
Actual behavior:
Playground Link:
https://www.typescriptlang.org/play/#src=type%20X%20%3D%20%7B%0D%0A%20%20id%3A%20%22primary%22%0D%0A%20%20inverted%3F%3A%20boolean%0D%0A%7D%20%7C%20%7B%0D%0A%20%20id%3A%20%22secondary%22%0D%0A%20%20inverted%3F%3A%20boolean%0D%0A%7D%20%7C%20%7B%0D%0A%20%20id%3A%20%22tertiary%22%0D%0A%20%20inverted%3F%3A%20false%0D%0A%7D%0D%0A%0D%0A%0D%0Aconst%20a%20%3D%20true%0D%0Aconst%20x%3A%20X%20%3D%20%7B%0D%0A%20%20id%3A%20a%20%3F%20%22primary%22%20%3A%20%22secondary%22%0D%0A%7D