我想知道我是否可以在 TypeScript 中使用条件类型?
目前我有以下界面:
interface ValidationResult {
isValid: boolean;
errorText?: string;
}
Run Code Online (Sandbox Code Playgroud)
但我想删除errorText
,而当只有它isValid
是false
一个必需的属性。
我希望我能够将其编写为以下界面:
interface ValidationResult {
isValid: true;
}
interface ValidationResult {
isValid: false;
errorText: string;
}
Run Code Online (Sandbox Code Playgroud)
但如你所知,这是不可能的。那么,您对这种情况有何看法?