Skip to content

Inconsistent behaviour of never within a mapped type #61602

@juhort

Description

@juhort

Acknowledgement

  • I acknowledge that issues using this template may be closed without further explanation at the maintainer's discretion.

Comment

Why are the results different in the following cases?

type T = { [K in keyof never]: string };
//   ^? type T = {}
type Keys = keyof never;
//   ^? type T = string | number | symbol

type T = { [K in Keys]: string };
//   ^? type T = {
//          [x: string]: string;
//          [x: number]: string;
//          [x: symbol]: string;
//      }

The second example makes sense to me — keyof never evaluates to string | number | symbol, so we get back index signatures as expected. But it's unclear why the first example produces an empty object instead.


Also, when generics are involved the result becomes never. This should also have been an index signature.

type Test<T> = { [K in keyof T]: string };

type T = Test<never>;
//   ^? type T = never

Metadata

Metadata

Assignees

No one assigned

    Labels

    Not a DefectThis behavior is one of several equally-correct options

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions