Skip to content

keyof to produce a runtime array #13267

Closed
@markboyall

Description

Put simply, I'd like a variant of keyof which produces the keys at runtime. E.g.,

interface Foo {
   prop1: number;
   prop2: string;
}

const x = keyof Foo;

In this case x should be ["prop1", "prop2"].

I've seen a few cases where people have tried to use keyof in somewhat-similar fashions, but they all wanted the actual keys present in the object at runtime. I however very explicitly want to ignore any properties present in any hypothetical runtime Foo objects that are not present in the interface.

Should permit generic parameters as the type.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Out of ScopeThis idea sits outside of the TypeScript language design constraintsSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions