react.d.ts: Change union type to intersection type#6926
react.d.ts: Change union type to intersection type#6926Strate wants to merge 2 commits intoDefinitelyTyped:masterfrom Strate:react_v014_react_instance_fix
Conversation
|
react/react.d.ts to authors (Asana (account can't be detected) AssureSign (account can't be detected) Microsoft (account can't be detected)). Could you review this PR? Checklist
|
…nent.props element
|
I fixed the tests, and I reverted change of |
There was a problem hiding this comment.
this is wrong; it should not be an intersection type; union was the right type. you have to narrow the type from Component<any, any> | Element to just Element to get your code to work
There was a problem hiding this comment.
I agree. This is definitely a type union
|
👎 |
|
Closed based on feedback |
|
ahh, I got it. It really can be either component or element, for base react elements, such as |
|
No problem |
type ReactInstance = Component<any, any> | Elementis wrong. Trying to accessing anyElement's property gives me a compilation error:This happening because of typescript union type spec:
Instead of using union type, there should be intersection type, which completely fits to this case:
So, there should be
type ReactInstance = Component<any, any> & ElementSee also #6205