gpt4 book ai didi

Typescript 将并集转换为交集

转载 作者:搜寻专家 更新时间:2023-10-30 21:26:07 24 4
gpt4 key购买 nike

<分区>

enum keyEnum {
firstKey = 1,
secKey = 2,
thirdKey = 3
};

enum firstPropEnum {
a = 'a',
b = 'b',
};

enum secPropEnum {
c = 'c',
d = 'd',
};

type firstAndSecPropEnum = firstPropEnum | secPropEnum;

type keyPropObj = {
[keyEnum.firstKey]: { prop: firstPropEnum },
[keyEnum.secKey]: { prop: secPropEnum },
[keyEnum.thirdKey]: { prop: firstAndSecPropEnum },
};

type getKeyProp<T extends keyEnum> = keyPropObj[T]['prop'];

type getKeyPropResult1 = getKeyProp<keyEnum.thirdKey | keyEnum.secKey> // Result secPropEnum | firstPropEnum
// Expected Result secPropEnum.
type getKeyPropResult2 = getKeyProp<keyEnum.thirdKey | keyEnum.firstKey> // Result firstPropEnum | secPropEnum
// Expected Result firstPropEnum.
type getKeyPropResult3 = getKeyProp<keyEnum.secKey | keyEnum.firstKey> // Result firstPropEnum | secPropEnum
// Expected Result never;

所以我期待得到一个交集而不是一个联合。结果应该是所有结果 Prop 共有的值。任何帮助都将不胜感激。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com