Closed
Description
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.