-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Allow JSX element attributes type to be an intersection #4362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Removing this restriction for the sake of intersection types makes sense. It was put in place because we don't really correctly support the JSX Attributes type being a union type. |
What should happen if it is an intersection of unions? Or an intersection of type parameters that could be instantiated to unions? |
A GlobalAttributes interface would be great because it would make it possible to add global attributes without redefining the entire typing file of for example react. |
What does this proposal allow exactly? The attributes type can be any type in the world? Or just an intersection of object types? Keep in mind that an intersection of object types would not fix the If the attributes can be any type in the world, what are the semantics for union types, primitives, tuples, and type parameters? |
My use case is the following: abstract class TestA<T> extends React.Component<{x:number}&T, {}> {
...
}
class TestB extends TestA<{y:number}> {
render() {...}
} Declaration works fine, but it can't be used because (I think) of the above problem. |
Fixed in nightly build |
@RyanCavanaugh Thank you! |
Consider the following:
This results in the error: JSX element attributes type '[type parameter] & { ref?: string; }' must be an object type.
An alternative would be an additional member of the JSX namespace that allowed specifying "global" attributes (that would apply to both value-based and intrinsic elements). For example:
See also DefinitelyTyped/DefinitelyTyped#5347
The text was updated successfully, but these errors were encountered: