Skip to content

typescript ReturnType is “any” if parameter type is “never” #40395

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

Closed
tylim88 opened this issue Sep 5, 2020 · 3 comments
Closed

typescript ReturnType is “any” if parameter type is “never” #40395

tylim88 opened this issue Sep 5, 2020 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@tylim88
Copy link

tylim88 commented Sep 5, 2020

I found alternative solution on stack overflow but was advised to open an issue here

TypeScript Version: 3.8.3

Search Terms:
ReturnType
Parameters
Function
any
never

Code

const abc = (a:never):number=>1
    
type a = ReturnType< typeof abc> //any

const abc2 = (a:number, b:never):number=>1

type a2 = ReturnType< typeof abc2> //any

Expected behavior:
type a and a2 should be number regardless of the types of parameters

Actual behavior:
type a and a2 are any if any of the types of the parameters are never

Playground
link

the original question is posted on here with details describing the use case
link

@jcalz
Copy link
Contributor

jcalz commented Sep 5, 2020

This is interesting:

type Expected = ((arg: string) => 0) extends (...args: any) => infer R ? "expected" : "unexpected"; // expected 
type Unexpected = ((arg: never) => 0) extends (...args: any) => infer R ? "expected" : "unexpected"; // unexpected
type Expected2 = ((arg: never) => 0) extends (...args: any) => any ? "expected" : "unexpected"; // expected
type Unexpected2 = ((arg: never) => 0) extends ((...args: any) => 0) ? "expected" : "unexpected" // unexpected

There's probably an existing issue for this but I didn't see one.

@MartinJohns
Copy link
Contributor

Duplicate of #35432.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Sep 9, 2020
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

5 participants