Skip to content

Change else clause to never in ReturnType #44669

Closed
@umireon

Description

@umireon

lib Update Request

Configuration Check

My compilation target is es5 and my lib is the default.

Missing / Incorrect Definition

The else clause of ReturnType is never reached because of the constraint so that it is reasonable to be never.

Sample Code

type T10 = ReturnType<() => string>;  // string
>T10 : string

type T11 = ReturnType<(s: string) => void>;  // void
>T11 : void
>s : string

type T12 = ReturnType<(<T>() => T)>;  // {}
>T12 : unknown

type T13 = ReturnType<(<T extends U, U extends number[]>() => T)>;  // number[]
>T13 : number[]

type T14 = ReturnType<typeof f1>;  // { a: number, b: string }
>T14 : { a: number; b: string; }
>f1 : (s: string) => { a: number; b: string; }

type T15 = ReturnType<any>;  // unknown
>T15 : unknown // changed from any

type T16 = ReturnType<never>;  // never
>T16 : never

type T17 = ReturnType<string>;  // Error
>T17 : never // changed from any

type T18 = ReturnType<Function>;  // Error
>T18 : never // changed from any

type T19<T extends any[]> = ReturnType<(x: string, ...args: T) => T[]>;  // T[]
>T19 : T[]
>x : string
>args : T

Documentation Link

https://www.typescriptlang.org/docs/handbook/utility-types.html#returntypetype

Changeset

I already made a changeset. I didn't know that a backlog issue is required to open a pull request.

https://github.com/microsoft/TypeScript/compare/main...umireon:returntype-never?expand=1

Duplicates

A possible duplicate is #39584 but nothing is discussed there.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions