-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Inferred type of generic parameter wrong in complex case involving mapped types #33568
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
What makes this bug more painful for us is that our real case involves a function with multiple type-parameters, the others of which are inferred correctly (and there's no way to skip type-parameter inference for only some type-parameters). |
This bug is related to the same infrastructure as #32608, but I don't think the bugs are actually related. We're just using enough "features" to be sensitive to type-checker changes, I guess. |
I was able to get it to compile without errors by just changing the type for type IRootResponse<TResponse> =
(TResponse extends IRecord ? { sendRecord:() => void } : unknown) & IResponse<TResponse>; It's not clear to me whether this solves your problem in general, though. It seems to mee that this should be an equivalent definition, but it seems to make the typechecker happier. |
Thanks @Nathan-Fenner - that work-around seems to work great in TypeScript 3.6. |
This is caused by #30287. Simpler repro: declare function ff(x: Foo<string>): void;
declare function gg<T>(f: (x: Foo<T>) => void): void;
type Foo<T> = T extends number ? { n: T } : { x: T };
gg(ff); // Error Above we make no inferences for |
TypeScript Version: 3.5.1 (also nightly, per playground)
Search Terms: mapped type interface generic parameter
Code
Sorry for the size of the repro. In TypeScript 3.3.3 this example-code type-checked without errors. As of (at least?) 3.5.1 and later I get the error:
Expected behavior:
The example program to type-check.
Actual behavior:
Example program does not type-check.
We can work-around this by supplying type-parameters to the invocation of exportCommand, however the (non-simplified) version of this bug comes up multiple times in our code-base, and it would be nice to infer the type-parameters from the passed-in callback (like we could prior to v3.5).
For the work-around, change the invocation of exportCommand
exportCommand<string>(save);
(fromexportCommand(save);
).Playground Link:
Related Issues:
The auto-issue searcher thing in GitHub found issues that sounded similar but are listed as affecting versions prior to 3.3 (where this code worked):
The text was updated successfully, but these errors were encountered: