We've built a type generator for Typescript that outputs types as follows:
type Def$9f45cffb = {
'title': string,
'subtitle': string,
'cta': Def$3f75f612,
};
type Def$3f75f612 = {
'variant': 'primary' | 'secondary',
'label': string,
'link': string,
};
type Def$46b580bc = {
'title': string,
'subtitle'?: string,
'cta': Def$3f75f612,
};
declare module 'component' {
type VerticalBannerV1_0 = Def$9f45cffb;
export interface VersionedComponentMap {
'vertical-banner': {
latest: VerticalBannerV1_0,
'1.0': VerticalBannerV1_0,
};
}
}
declare module 'slot' {
type HomeBannerV1_0 = Def$46b580bc;
type HomeBannerV2_0 = Def$9f45cffb;
export interface VersionedSlotMap {
'home-banner': {
latest: HomeBannerV2_0,
'1.0': HomeBannerV1_0,
'2.0': HomeBannerV2_0,
};
}
}
Notice that types are reused between the two mappings to avoid duplication. This works pretty well, except that the aliases are expanded, making debugging a nightmare:
I know that TypeScript doesn't offer guarantees about preserving type aliases. I'm looking for a workaround for this issue to provide a better developer experience.
My goal is to prevent aliases from getting expanded so HomeBannerV2_0
would not become Def$46b580bc
, for example.
This is what I get currently for type example = VersionedSlotMap['home-banner'][keyof VersionedSlotMap['home-banner']]; }
:
Def$46b580bc | Def$9f45cffb
And this is what I want:
HomeBannerV1_0 | HomeBannerV2_0