Script - Conditional Types
445 ワード
タイプは条件付きで使用できます.
interface Animal {
live(): void;
{
interface Dog extends Animal {
woof(): void;
}
}
type Ex1 = Dog extends Animal ? number : string;
console.log(typeof Ex1) // number
type Ex2 = RegExp extends Animal ? number : string;
console.log(typeof RegExp) // string
条件タイプには次の条件があります. SomeType extends OtherType ? TrueType : FalseType;
Reference
この問題について(Script - Conditional Types), 我々は、より多くの情報をここで見つけました https://velog.io/@changchanghwang/TypeScript-Conditional-Typesテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol