TypeScript 不正确的类型处理/约简

disbfnqx  于 6个月前  发布在  TypeScript
关注(0)|答案(3)|浏览(66)

🔎 搜索词

withTranslation, reduxForm, IntrinsicAttributes

🕗 版本与回归信息

  • 这是我尝试的每个版本(支持此类型检查)的行为,我查阅了关于条目的FAQ。

⏯ 代码沙盒链接

https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAJQKYEMDG8BmUIjgcilQ3wG4AoUSWOAbziIBMBXADwDFoQAaOASQB2AKyQYkjTlBAAFHGADOcAL5xsuAkzYBaTFzKVw0ePQDuwGAAsAKlBQD5AGxQxgEAbwDq567ftOXbsqqOHiExDBawACMABwCSKww+uQwAJ5gSHBWshAKcAC8dHBgAFxwAswgAEZIUMoUaRlZkiDswEgOjIqF9ADWAPxlFdW19SnpmVYAgg4OOXmF2XKKAGRwXpY2do7OrgINE1lWBVkzc8twa4IiYhJc8-IAPFYtbR1dvNOzDwB8FORoNzyeAAcROAAppGUrFYAJQFH5wR6gADmcBQDhg+VoAGUYFBgAIUZCAHRgWEqAD0fwBQNBLXEJ00HC4z1e7U68k+Z1+4PouikZXwmHwylh4JBsIogPs9K4JzMm18OwCAnB4pBDMYUvI5AS1HgMuBcHYEPh+URj018rA2KiVL+QA

💻 实际行为

它抱怨最后一行,关于 p={1} -
Type '{ p: number; }' is not assignable to type 'IntrinsicAttributes & Omit<Subtract<DecoratedFormProps<TFormFields, TAllProps, string> | undefined, WithTranslationProps>, keyof WithTranslation<...>> & WithTranslationProps'.
Property 'p' does not exist on type 'IntrinsicAttributes & Omit<Subtract<DecoratedFormProps<TFormFields, TAllProps, string> | undefined, WithTranslationProps>, keyof WithTranslation<...>> & WithTranslationProps'.
这是错误的或无意义的,因为我使用的所有这些类型都会从我传递的类型中添加或省略它们的高阶组件类型,所以 ComponentType<TProps> 应该最终成为 GForm 的类型,但它不是

🙂 预期行为

没有类型错误

nnsrf1az

nnsrf1az1#

const GForm = 行更改为 const GForm = withTranslation()(GFormed) as ComponentType<TProps>; 可以消 debugging 误。

v2g6jxz6

v2g6jxz62#

这可能是其中一个依赖项中的类型的问题。请提供一个简化的(隔离的)复现案例 - 实际上,我们无法以人类的方式查看目标类型并评估是否有问题。

pcww981p

pcww981p3#

我希望能够进一步减少它,这个代码更容易调试吗?
https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAJQKYEMDG8BmUIjgcilQ3wG4Aoc0SWOAbzgGFdIA7JVmAGiZYnc4AVAJ5gkcAL5xsuOACIi6GHIrkAJkjQAbFETjBOSKJnTiAkqwBWmmEjUAxaCAAKOMAGd65OD+lOAIprQKDDA-PbASFpqAFz0EuQJ6po6ega2xqZwjlAgFu4wKKxoSAA8zgB8cEgAHrasap7M4PwcMOVVdN6+mE75hcVIcXQJScnauuIwouKBaMG2Dk4AyoW2cAC8Xr5+uXMLYawRUbHxiaoaE3rTYnD7UCF2OS5u7uWb8VUb3T4AZHDOH5wf7OXShFBaUr3R5LXKrR4VC4pSb6QyZEp3IIPRbNNhtRg6dxvSrbXzsADuAAowK8APxxZw8eaGOr0uBFYQASjiz36RRKHQoSUuqSmM2yASxIWgHQ+lKB8xaAhgcVxrSEM3e-ws1gwTycrggHgqXHInM2VWhOL4yoJKCJUKli2eho8HURlBFKMwAFdiqF+HAiGofTVnu8tiMKvLuRK9k6ZZVVFQWrQbuIuj5gABGAAcrFNPkE9j9GEOpqkMjw+Bz+dqMDIlHGotRGRMGIA6sAYAALQQPVjuHQB1iklVwYulkcULN51hxWusGdwGDIFBqYRxABGEAgWlQS8SnuRaTR7fEXd7-aKQ5Ch1dnkz+jnbMXy597iQyw-YkHSDZO57geQrHlc4i+v6hxwOS3Z9gOt4juQ8o+EaI7uGyT4+DBvbIJgAG7vuRTLhIpqxqU3SMNUdQcI0iDEDAAB0arKiIYilGuGBMTabQPqUHJVP8l5wTew73q8JrdMg7h7gAbnYD4fAAUssAAaDEADLAFuDxQMIACyRQoAA5nYACCMAwFAWk+rYbxAowha+AA8iA3bsfRXFKjxrylIwJpwAA1kgw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