Skip to content

Object.fromEntries: return type does not account for symbols #44405

Closed
@mfulton26

Description

@mfulton26

fromEntries<T = any>(entries: Iterable<readonly [PropertyKey, T]>): { [k: string]: T };

const record = Object.fromEntries([[Symbol.for("1"), "hi"]]);
console.log(record[Symbol.for("1")]);
error: TS2538 [ERROR]: Type 'symbol' cannot be used as an index type.
console.log(record[Symbol.for("1")]);
                   ~~~~~~~~~~~~~~~

the return type should account for objects built with symbols for keys (e.g. through a generic type or something)

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