Unexpected behaviour using Index type with Union type signature

后端 未结 1 838
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-02 01:05

I have a data structure where one of the keys allows for a dynamic set of values. I know the potential type of these values but I am unable to express this in Typescript.

相关标签:
1条回答
  • 2020-12-02 02:00

    It is true that a union is inclusive, so A | B includes anything which is a valid A, and anything which is a valid B, including anything which is a valid A & B. TypeScript doesn't have negated types, so you can't say something like (A | B) & !(A & B), which would explicitly rule out anything which matches both A and B.

    0 讨论(0)
提交回复
热议问题