-
Notifications
You must be signed in to change notification settings - Fork 12.8k
ReturnType<> broken with never in parameter (please revisit) #35432
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 disagree and don't see any case being made here. A function that expects a What problem is this causing for you? |
The original issue I linked to actually explains the case. But I'll just explain again. The use case is precisely that I don't want the function to be invoked externally, but I want to preserve the return type information only. interface IQuery<DataT extends QueryData> {
someNonGenericProp : string;
mapDelegate : DataT["mapDelegate"];
} An object of the above interface is returned after using a query builder. The The return type information is important, the argument type information must be erased (faster emit, not meant to be invoked) This This function needs to know the return type of
At the moment? I have a workaround But each workaround I use just makes the code harder to read and understand, a few weeks down the road. I didn't realize this was the current behavior; that I only caught it because I wrote some compile time tests and noticed it. Then I had to figure out what was causing it, then I had to figure out a reasonable workaround. |
The TS code base uses I don't think it's unreasonable to expect |
A function of type I think the problem is already covered in existing issues and boils down to
|
In my PR/workaround, I'm using, type ReturnType<T extends (...args: any) => any> = T extends (...args: never) => infer R ? R : any;
Because Using |
TypeScript Version: 3.7.2
Search Terms:
parameter, never, ReturnType
Code
The
AnyFunction
type is found here:TypeScript/src/compiler/core.ts
Line 1464 in c447ebc
Expected behavior:
x
should bevoid
Actual behavior:
x
isany
Playground Link:
Playground
Related Issues:
Original Issue:
#33457
PR to fix
ReturnType<>
:#33496
@jack-williams tracking the
never
and rest params issue:#33495
The text was updated successfully, but these errors were encountered: