-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
QuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code
Description
I came across a functionality I needed and I couldn't really find a solution out there.
Interfaces have an easy Pick functionality. However, enums and types don't
This is what I had to do to Pick the keys out of an enum. [Which I used in a select/dropdown]
It would be nice to have a pick like that build in.
perhaps something like this:
enum KeysToBePickedFrom {
KEY_ONE = "Key One",
KEY_TWO = "Key Number Two",
KEY_THREE = "Another key n. 3",
LAST_KEY= "Here is the last Key"
}
// desired pick functionality
interface Picked {
y: Pick<keyof KeysToBePickedFrom, 'KEY_ONE', 'LAST_KEY'>
}
const z: Picked = {
y: "KEY_ONE" // KEY_ONE | LAST_KEY
}current workaround implementation:
enum KeysToBePickedFrom {
KEY_ONE = "Key One",
KEY_TWO = "Key Number Two",
KEY_THREE = "Another key n. 3",
LAST_KEY= "Here is the last Key"
}
type KeysOfEnum_KeysToBePickedFrom = {[key in keyof typeof KeysToBePickedFrom]: string }
type Picked_KeysOfEnum = Pick<KeysOfEnum_KeysToBePickedFrom, 'KEY_ONE' | 'LAST_KEY' >
interface KeysPickedForType {
keyone: Picked_KeysOfEnum
}
const picks: KeysPickedForType = {
keyone: "KEY_ONE" // KEY_ONE | LAST_KEY
}Anyone with a better approach or a point to a built-in functionality in the docs?
Thoughts?
korniychuk, shubhamkakkarArv, tcd, codercodingthecode, lanistor and 1 moreAnyhowStep and sebastienguillon
Metadata
Metadata
Assignees
Labels
QuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code