-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Type inference issue JSX with generic #30057
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
I'm not seeing the same error (or any error) when I try to make a repro - what are your compiler options? |
Actually, hold on (well, maybe in addition to that question), that looks like VS - what version of the typescript SDK do you have installed in VS? IIRC the TS version installed in your project by |
Hi. Also happens via
Same with TSC 3.4.0-dev.20190222. |
(As in #27986 |
Oh, that's interesting: My "more simple repro" from the comments does not emit an error. (Only the full sample in the issue description.) |
@weswigham Did you have a look on this? Atm. this prevents me from upgrading to React 16.8 (typings). |
Minimal repro without involving // @strict: true
interface Box<T> {
v: T;
}
interface ErrorResult {
readonly error: true
}
interface AsyncLoaderProps<TResult extends {}> {
readonly asyncLoad: () => Box<TResult>;
readonly children: (result: Exclude<TResult, ErrorResult>) => string;
}
class AsyncLoader<TResult extends {}> {
constructor(props: string, context: any);
constructor(props: AsyncLoaderProps<TResult>);
constructor(...args: any[]) {}
}
function load(): Box<{ success: true } | ErrorResult> {
return null as any;
}
new AsyncLoader({
asyncLoad: load,
children: result => result.success as any,
}); // should work fine eliminating either |
Many thanks for having a look. And thanks for the hint with the c'tor workaround! |
@weswigham Thank you very much for the fix! |
I believe I am seeing this issue with TS 3.4.5 This file fails to compile: import React from 'react';
interface IErrorProps {
error: string;
}
export default function foo<TErrorProps extends IErrorProps>(
ErrorCmp: React.ComponentType<TErrorProps>
) {
return class extends React.Component {
render() {
return <ErrorCmp error="test error" />;
}
}
} with the error But if I downgrade to TS 3.1.4, it compiles without issue. This happens for me whether I have |
My above comment is not correct, it looks like I am seeing an improvement/bug fix from TS 3.1 to 3.2, more info here: https://stackoverflow.com/questions/55942402/when-using-generic-react-components-get-error-in-ts-3-2 |
TypeScript Version: 3.3.3333
This is a follow-up for #27986 (see also this comment). It already has been fixed and the type inference worked fine since then. But now, the exact same compiler error (see original issue for code snippet) appeared after updating
@types/react
:I've tacked it down and it happened exactly with
@types/react@16.7.21
(version@types/react@16.7.20
and before works).I've generated a diff of these two versions: Compare.pdf
And here are the full packages: both_versions.zip
The text was updated successfully, but these errors were encountered: