-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Regression for inferred unions in generic parameters #33490
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
Oh and -component: C & ComponentType<P>
+component: C & (C extends ComponentClass<P> ? ComponentClass<P> : FunctionComponent<P>) fixes any error and passes the full test suite down until 3.0. 3.1 and above will pass while 3.0 will fail. |
I'm just trying to use jsdoc in vscode (v1.38.1) to document types and the following doesn't work. Is this the same bug? My issue is that Intellisense shows /** @param {string | number | (zzz:string)=>string} yyy */
function xxx(yyy) {
return yyy;
} Intellisense shows /** @param {(zzz:string)=>string} yyy */
function xxx(yyy) {
return yyy;
} Intellisense shows
|
@waynebloss your first code should be wrote as (see the parenthesis around lambda): /** @param {string | number | ((zzz:string)=>string)} yyy */
function xxx(yyy) {
return yyy;
} |
I suspect this regressed because of #32558. |
Simpler repro: type AB<T> = { a: T } | { b: T };
// T & AB<U> normalizes to T & { a: U } | T & { b: U } below
declare function foo<T, U>(obj: T & AB<U>): [T, U];
declare let ab: AB<string>;
let z = foo(ab); // Expect [AB<string>, string] Regression was indeed caused by #32558. |
TypeScript Version: 3.7.0-dev.20190918
Search Terms: infer generic
Code
C & ComponentType<P>
helps inference. For a more comprehensive test suite check the react-router declarations and testsA fix getting rid of
C & ComponentType<P>
(DefinitelyTyped/DefinitelyTyped#38326) caused issues when usingstrictFunctionTypes
Expected behavior:
No type error
Actual behavior:
Throws with a different error message depending on the order of the union members in
ComponentType
Playground Link:
playground for 3.5.3
Related Issues:
withRouter
fails withComponentType
starting in 3.6.2 DefinitelyTyped/DefinitelyTyped#38271/cc @OliverJAsh
The text was updated successfully, but these errors were encountered: