Skip to content

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

Closed
@tylim88

Description

@tylim88

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions