Issue
Having an object similar to this:
const obj = {
1: "one",
2: "two",
3: "three",
}
type Keys = keyof typeof obj; // type of Key is 1 | 2 | 3
how do I get Keys
to be of type (strings) "1" | "2" | "3"
in order to have autocomplete ?
Solution
You could use template literal types
const obj = {
1: "one",
2: "two",
3: "three",
}
type Keys = `${keyof typeof obj}`;
const value: Keys = "1";
Answered By - axtck
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.