-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Second infer overwrites initally infered type defintion #32389
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
Here is a more minimal example type Infer1<T> = () => T;
type Infer2<T> = T extends ArrayLike<infer S>
? (a: S) => Partial<S>
: (a: T) => Partial<T>;
declare function f<T>(infer1: Infer1<T>, infer2: Infer2<T>): void;
declare function f1(): Array<{ a: any }>;
f(f1, a => a); I expect Interestingly this modified example, where |
I found a workaround that at least for now solves my problem by changing type Infer2<T> = T extends ArrayLike<infer S>
? <SS extends S>(s: SS) => Partial<SS>
: <TT extends T>(t: TT) => Partial<TT>; I'm not sure if this could have undesired side-effects, but at least it allows me to continue. |
@clentfort If you want a workaround using type Infer1<T> = () => T;
type Infer2<T> = T extends ArrayLike<infer S>
? (a: S) => Partial<S>
: (a: T) => Partial<T>;
declare function f<T>(infer1: Infer1<T>, infer2: Infer2<T & {}>): void;
declare function f1(): Array<{ a: any }>;
f(f1, a => a); Your workaround makes the second parameter a generic function, which will behave differently. For example this would not be legal: type Infer1<T> = () => T;
type Infer2<T> = T extends ArrayLike<infer S>
? <SS extends S>(s: SS) => Partial<SS>
: <TT extends T>(t: TT) => Partial<TT>;
declare function f<T>(infer1: Infer1<T>, infer2: Infer2<T>): void;
declare function f1(): { a: any };
f(f1, (s) => ({ a: 1 })); // concrete value assigned to a generic type not allowed. |
Thanks for pointing this out, this means my workaround is exactly what I want. :) |
See #30134 - the particular use of depending on an |
TypeScript Version: 3.5.1
Search Terms:
Infer, Multiple, Generic
Code
Expected behavior:
Allowed return type of
unpackSuccess
should be asMyPayload[]
Actual behavior:
Allowed return type of
unpackSuccess
is beMyPayload
.Playground Link
Related Issues:
I tried to search for related issues but could not find anything, maybe I don't know the correct terminology.
The text was updated successfully, but these errors were encountered: