Skip to content

Tooltip for mapped type displays number key instead of string #47214

@ASDFGerte

Description

@ASDFGerte

Bug Report

Unlikely this hasn't been already mentioned before, but i couldn't find anything.

A mapped type using string keys which represent numbers displays these as numbers in the tooltip.

type A = { [K in '0']: number }; // { 0: number }
type B = { '0': number };        // { '0': number }
type C = { 0: number };          // { 0: number }
type Atest = '0' extends keyof A ? 'yes' : 'no'; // 'yes'

🔎 Search Terms

mapped type tooltip displays number string key

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about #common-bugs-that-arent-bugs

⏯ Playground Link

Playground link with relevant code

🙁 Actual behavior

Tooltip displays

type A = {
    0: number;
}

🙂 Expected behavior

Tooltip displays

type A = {
    '0': number;
}

PS: I'd prefer it even more, if TS stopped allowing keys being some subtype of number altogether, but i guess that's a different topic.

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