export type Message = [
{
id: 'message',
settings: ComponentSettings;
}
];
type Industrial = [
{
id: 'title',
settings: ComponentSettings;
},
{
id: 'text',
settings: ComponentSettings;
}
];我希望仅当T为'Message | Industrial‘时才允许T
export interface CardRef<T> {
id: 'Industrial' | 'Message';
childInstances?: T;
}发布于 2020-04-26 19:36:50
听起来您可能希望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 | undefinedhttps://stackoverflow.com/questions/61439824
复制相似问题