Enrich TypeScript Utility Types #39305
Labels
Declined
The issue was declined as something which matches the TypeScript vision
Suggestion
An idea for TypeScript
Search Terms
Distributive keyof, ValueOf, PickWhen, OmitWhen
Partial results...
KeyOf
andValueOf
definitions to built-in lib #31438Suggestion
I'd like to see TypeScript default typeset richer so that some common takes comes handy and universal.
KeyOf<U, C?, K?>
In #31438, I stressed the need to collect keys or union type. Today, I have it evolve by supporting conditions on the value they map to. I can collect all the keys of an entity that maps to another entity and array of entities.
e.g:
ValueOf<U, K?>
Also in #31438 also, I suggested this type along the
KeyOf
. Again, I augmented it today with the ability to narrow down which keys to pick, if applicable to the union member.e.g:
PickWhen<U, C?, K?>
Pick
does quite a great job by containing on the keys,PickWhen
proposes to constrain on the value type, while still allowing to narrow down the keys to picking from, and keeping the union structure.e.g:
OmitWhen<U, C?, K?>
OmitWhen
it toOmit
whatPickWhen
is toPick
e.g:
Use Cases
Provided along with each proposed type.
Examples
I have put it all together here, on TypeScript Playground.
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: