TypeScript/tests/cases/compiler/inferenceUnionOfObjectsMappedContextualType.ts
Wesley Wigham a91c2879ef
Allow discrimination to identical object types when discriminating contextual types (#40574)
* Merge identical object types when discriminating contextual types

Co-authored-by: Orta <ortam@microsoft.com>

* Allow identical discriminants when discriminating, rather than trying to unify identical union members

* Fix lint

Co-authored-by: Orta <ortam@microsoft.com>
2020-09-23 00:51:14 -07:00

17 lines
516 B
TypeScript

// @strict: true
type Entity = {
someDate: Date | null;
} & ({ id: string; } | { id: number; })
type RowRendererMeta<TInput extends {}> = {
[key in keyof TInput]: { key: key; caption: string; formatter?: (value: TInput[key]) => string; };
}
type RowRenderer<TInput extends {}> = RowRendererMeta<TInput>[keyof RowRendererMeta<TInput>];
const test: RowRenderer<Entity> = {
key: 'someDate',
caption: 'My Date',
formatter: (value) => value ? value.toString() : '-' // value: any
}