Skip to content
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

As a developer I want the JSX support in N4JS to not ignore the properties of JSX elements/fragments #2118

Open
mor-n4 opened this issue Apr 14, 2021 · 0 comments

Comments

@mor-n4
Copy link
Contributor

mor-n4 commented Apr 14, 2021

Currently, the JSX support in the N4JS compiler is producing raw types as the types of JSX elements. This is a problem because raw types are checked only partially and should therefore be used only in rare special cases.

For example:

import * as React from "react";

interface ~FooProps extends React.ComponentProps {
	public fooProp?: string;
}
interface ~OtherProps extends React.ComponentProps {
	public otherProp: string;
}

function Foo(props: FooProps): React.Element<?> {
	return null;
}

let fooTag = <Foo/>;

// XPECT FIXME errors --> "Element<FooProps> is not a subtype of Element<OtherProps>" at "fooTag"
let elem: React.Element<OtherProps> = fooTag; // this assignment should not be allowed!!

The type of fooTag will be Element (i.e. a raw type not providing a type argument for Element's type parameter), leading to the problem that the assignment in the last line is allowed. Instead, the type of fooTag should be at least Element<?>, or better Element<MyProps>.

The problem, however, is that this fix will break client code because it leads to stronger type checking.

@mor-n4 mor-n4 changed the title As a developer I want the JSX support in N4JS to not ignore PropsT of JSX tags As a developer I want the JSX support in N4JS to not ignore the properties of JSX elements/fragments Apr 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant