* 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>
17 lines
516 B
TypeScript
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
|
|
}
|