Skip to content

Add KeyOf and ValueOf definitions to built-in lib #31438

Closed
@SalathielGenese

Description

@SalathielGenese

Search Terms

None -
Empirical experience -

Suggestion

I want to see added KeyOf and ValueOf

Use Cases

Let them distribute union

let a_or_b_002!: KeyOf<{ a: 'Aa' } | { b: 'Bb' }>;      // "a" | "b"
let a_or_b_003!: KeyOf<({ a: 'Aa' } | { b: 'Bb' })>;    // "a" | "b"

Examples

let a_or_b_002!: KeyOf<{ a: 'Aa' } | { b: 'Bb' }>;      // "a" | "b"
let a_or_b_003!: KeyOf<({ a: 'Aa' } | { b: 'Bb' })>;    // "a" | "b"

instead of

let a_or_b_001!: keyof ({ a: 'Aa' } | { b: 'Bb' });     // "a" & "b"

Checklist

My suggestion meets these guidelines:

  • [x ] This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • [ x] This wouldn't change the runtime behavior of existing JavaScript code
  • [ x] This could be implemented without emitting different JS based on the types of the expressions
  • [ x] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • [x ] This feature would agree with the rest of TypeScript's Design Goals.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DeclinedThe issue was declined as something which matches the TypeScript visionSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions