mirror of
https://github.com/hanzoai/tsgo.git
synced 2026-10-30 19:37:15 +00:00
44 lines
795 B
TypeScript
44 lines
795 B
TypeScript
//// [tests/cases/compiler/discriminatedUnionWithIndexSignature.ts] ////
|
|
|
|
//// [discriminatedUnionWithIndexSignature.ts]
|
|
export interface UnionAltA {
|
|
type?: 'text';
|
|
}
|
|
|
|
export interface UnionAltB {
|
|
type?: 'image' | 'video' | 'document';
|
|
}
|
|
|
|
export type ValueUnion = UnionAltA | UnionAltB;
|
|
|
|
export type MapOrSingleton =
|
|
| {
|
|
[key: string]: ValueUnion;
|
|
}
|
|
| ValueUnion;
|
|
|
|
const withoutAsConst: MapOrSingleton = {
|
|
1: {
|
|
type: 'text' /*as const*/,
|
|
},
|
|
};
|
|
|
|
const withAsConst: MapOrSingleton = {
|
|
1: {
|
|
type: 'text' as const,
|
|
},
|
|
};
|
|
|
|
//// [discriminatedUnionWithIndexSignature.js]
|
|
const withoutAsConst = {
|
|
1: {
|
|
type: 'text' /*as const*/,
|
|
},
|
|
};
|
|
const withAsConst = {
|
|
1: {
|
|
type: 'text',
|
|
},
|
|
};
|
|
export {};
|