export type Message = [
{
id: 'message',
settings: ComponentSettings;
}
];
type Industrial = [
{
id: 'title',
settings: ComponentSettings;
},
{
id: 'text',
settings: ComponentSettings;
}
];
仅当T为'Message |时,我才允许T工业”
export interface CardRef<T> {
id: 'Industrial' | 'Message';
childInstances?: T;
}
答案 0 :(得分:2)
听起来您可能希望CardRef
是联合类型,而不是带有通用参数的类型:
export type CardRef =
{
id: 'Industrial';
childInstances?: Industrial;
}
|
{
id: 'Message';
childInstances?: Message;
};
用法:
let x: CardRef = { id: 'Industrial' };
x.childInstances; // type is Industrial | undefined
let y: CardRef = { id: 'Message' };
y.childInstances; // type is Message | undefined