There seems to be a problem with unions and literal types when both types of the union contain a field with the same name.
TypeScript Version: 2.5.2
Code
The small example
classA{field: 42;}classB{field: number;otherfield: number;}// Gives an errorletx: A|B={field: 42};// Type '{ field: number; }' is not assignable to type 'A | B'.// Type '{ field: number; }' is not assignable to type 'B'.// Property 'otherfield' is missing in type '{ field: number; }'.The simple example of a more realistic situation (typeorm-ish code)
typeOrderBy='ASC'|'DESC';typeSimpleOrderByCondition={name?: OrderBy;randomField?: OrderBy;};typeOrderByCondition=SimpleOrderByCondition|(()=>SimpleOrderByCondition);// Works OK as expectedletorderBy1: OrderByCondition={randomField: 'ASC'};// gives an error. But, it should work.letorderBy2: OrderByCondition={name: 'ASC'};Expected behavior:
No error
Actual behavior:
[ts]
Type '{ name: string; }' is not assignable to type 'OrderByCondition'.
Type '{ name: string; }' is not assignable to type '() => SimpleOrderByCondition'.
Type '{ name: string; }' provides no match for the signature '(): SimpleOrderByCondition'.
There seems to be a problem with unions and literal types when both types of the union contain a field with the same name.
TypeScript Version: 2.5.2
Code
The small example
The simple example of a more realistic situation (typeorm-ish code)
Expected behavior:
No error
Actual behavior: