Strict version of Extract for literal union types #31474
Labels
Awaiting More Feedback
This means we'd like to hear from more people who would be helped by this feature
Suggestion
An idea for TypeScript
Search Terms
extract, pick, union, literal, string
Suggestion
Currently we have
Pick<T, K>
to select a type-safe subset of a given typeT
using a union of keysK
. Unfortunately this does not work for unions of literals and requiresExtract
which subjectively isn't strict enough:One caveat is that
Extract
does not support code completion when writing the literal union for the keys and it allows keys not in the first type as well. The former is error-prone while the latter is not causing a different behavior since the illegal keys are ignored but it can't be strictly checked in the long run. Of course I understand there are use cases wherein you'd like to useExtract
more liberally so the definitionis reasonable enough. Nevertheless, I'd like to propose an additional strict variant as follows
Use Cases
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: