Bug报告:
🔎 搜索词
类型 predicate
Map类型
联合类型
Map类型 predicate
🕗 版本与回归信息
4.9.3 & 4.9.4
- 这是我在每个版本中尝试的行为,我查看了关于Map类型 predicate 的FAQ条目
⏯ 编程环境链接
https://www.typescriptlang.org/play?#code/PTAuAsFMAIwHMHsCGAbaBLAztU86QHaQBOioMoAngA4xVGQAmaAxqTAGYCu+zoa8+LO3hFoifNHgAjAFaRe0bv3wAaaEwzMiaALZp8bBtCkUx0DKG35Y0ZGjIlU7NJGQMAXNACSEiJmisGORQ0M6uRgBElDQRAFAgEDBSnDb+pNghBEbw7Lb6MAAsAIxqEQCC2NS09EysZYoAHsimKMjwAO6M6BL0oJxEvlXQVPAY9sqhIqHcvMpY4kY6kBDwDBgRAHTQAKIAbgQZ8Cng6KAN3Rkwvf0SI2N8ApOiiNM8D-ixyMvq8MyeAKr4ZQABRqLDYGAAPAARABC0N+AD5oABeaD4TjIVCIeb4CggDFYp7YSAWfQ2Kj9O6ktTtNBEqQwXRUL5LfBkIx0iDQABSAGVhkR4AAPUzSOS8WJodgACgYvw2mAAKlUvDpYMDRqAZQBKHUAb1i0GNAQEGHgXw2bVgcoVukQsEg-yIyB1AG5YgBfaCuILoWXy5iKjAqmiarGaiy6g1Gk3MM0WyBW+A2wMbPigL7ur2xWLRGBKyDC0AAWVJGAdMDRhpN0AA+mgPOZLOTY8b854AORkYsljCwTtt0JCnT-IJETwWKywIc4MfESct6yz3SQPmgRA6KieDE6RlEIdLDAVx2L6c5-PeHSVyNnatDhtNqet2sd6Cd3QarWD2v2x3O5AzxfE1MAANUwNApC+TwpHgRNxCHLRIEMMpQB3Tg92IC8hnDZBb1RaAaxNR8gOXV8qi7EYI2-FdM0gUiZ1reAqHeDAGIAbQAXSHXZ4DINj0Qw-cuOwmhoDhBFmAIwte3LStoAAHyvG8tUU6BcNvXMtMvQEQTBOpSUhJVkTRABheAdB0AQAGlIAoKEAHl8GaddpwAGXsYgUAAMRcNwoWM5EizIfA1mbadoAAfmg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H4MKTo8p2AiCRyHETHqtV6rvOatsYUzBkCcAYLLL56lmLgqqtADmuL4UVTnhsMoBshyeBKaS8lyyVnwrqtsn6uzlBDNATKQ59djnKM2ucs2lz4BzJuaYkZMohy8u6NPbwsQLlXNhdK2swqPSOIcbEIAA
4条答案
按热度按时间a8jjtwal1#
我认为你只需要去掉
T is Other
周围的括号。tjrkku2a2#
类型 predicate 缩小了 值 的类型。缩写示例没有意义,因为你试图引用一个类型,但是通过Playground,很明显你想做的就是在Map类型中使用一个
this
类型,这确实有意义:$x_1^a_0b_1^x$
mqkwyuun3#
真正奇怪的是,如果你在playground中修复了你的语法错误(如@fatcerberus所说,删除括号),代码会按照你的预期工作,但我们仍然会收到错误信息,提示
this
类型不允许在类或接口之外使用。从调查旧的bug来看,我认为这个消息有两个目的:this
类型是没有意义的this
类型看起来是模糊的当
this
类型模糊时,它根本不会解析(我们返回错误any
)。但是在其他一些没有歧义的地方,存在一个对象类型,我们会发出一个错误,但类型确实可以解析:https://www.typescriptlang.org/play?#code/PTAEDkHsBdQSwHYGc4BMCmoCGoDGAbLJJUSAJ3gWnTIDMtd0AaAKBFACMBXWLhLALYc4Acy6QuJRNgSkOAK3S5Y0AJ4AHTPjjUyWfCwwEsZLeli1IkAFygA3i1BPQACyIAhE7YAUASlAAvAB8oNAucFIkdpxeoAhcQjSgAL4sqXC0oN6WkAB0bkieZH7+Ds6gObkcJgDcjs7sAHoA-GksLIi69IygAGJW9vVO7Agw2Pj4kADu6Kig6lym+KqcSliSmDoA5CSCwmISSEygAJKgYujEQ9hCouKSfrbRAB62YREpbYZKhKag+OYKrZ+pA6rRcns7oc-LlnmwwOVEU4WkA我不太确定,但这确实让人感觉这个限制的一部分是人为的,可以被取消。
1yjd4xko4#
非常感谢反馈!@fatcerberus 你说得对,@andrewbranch 谢谢你没有将此问题视为语法错误。是否可以通过AST转换器实现?