Skip to content

keyof as object keys #19027

@milewski

Description

@milewski

is it possible to set something like this with typescript?

interface SomethingElse {}

type Fruits = {
    banana: boolean,
    apple: boolean,
    melon: boolean,
    //.... 1000 records
    grape: boolean
}

const list: { [key: keyof fruits]: SomethingElse }

what i am trying to archive here is reuse the keys from fruits to create a new type that is no longer boolean, as you see i could create a new interface/type where i could assign the type as SomethingElse however that means i would need to duplicate all the fruits keys........

would it fit in a feature request? or you guys think this is non sense?

Metadata

Metadata

Assignees

No one assigned

    Labels

    ExternalRelates to another program, environment, or user action which we cannot control.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions