目前是这么写的:
interface ContentA {
name: string;
age: number;
}
interface ContentB {
name: string;
hobby: string;
}
// 接口响应数据的类型
interface ResponseData {
type: '0' | '1';
content: ContentA | ContentB;
}
当type为0时,希望content是ContentA,为1时是ContentB,如何动态限定?
如果只有两种情况的话,可以这样写并且很简单易懂。