Skip to content

Object key type should be forced to be a string (index signature parameter)Β #44577

@rosenbergd

Description

@rosenbergd

Bug Report

πŸ”Ž Search Terms

Object key type, index signature parameter type

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I believe it should act differently

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

const a: {[prop: number]: number} = {};

a[1] = 123;

for (const i in a) {
    console.log(a, a[i], typeof i);
}

πŸ™ Actual behavior

I'm allowed to set the prop key to type number, but it is actually a string when tested

πŸ™‚ Expected behavior

It should not allow me to use number as the type for the key properties as it automatically converts to string anyways which could create confusion

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