如何通过使用Typescript中的属性指定并集之一

时间:2018-10-09 09:44:51

标签: typescript

type Identification =
    {
            readonly isIdentified: false;
      }
    | {
            readonly isIdentified: true;
            readonly phoneNumber: string;
            readonly birth: Date;
            readonly gender: boolean;
      };
type propertyName = keyof Identification;
var name: propertyName = "gender"; // Type '"gender"' is not assignable to type '"isIdentified"'

如何指定具有性别属性的工会类型之一?

0 个答案:

没有答案