'Template Literal type equivalent
Good morning,
I have an enum like so:
export enum ApiFunctions {
"setHidden" = "HIDE",
"setReadOnly" = "SET_READ_ONLY",
"setVisible" = "SHOW",
"setDescription" = "SET_DESCRIPTION",
"setName" = "SET_NAME",
"makeRequest" = "MAKE_REQUEST"
}
Earlier today I created a new type from this enum like so:
export type ApiActions = Exclude<`${ApiFunctions}`, "MAKE_REQUEST">
This type returns all the values of the keys except "MAKE_REQUEST" (SET_DESCRIPTION,....)
The problem is Template literal types were released on ts 4.1 and the current bundler's ts version is 3.9.7 and I can't really update it since it is externally provided.
I have tried replicating this type by doing:
export type Something = Exclude<typeof ApiFunctions[keyof typeof ApiFunctions], "MAKE_REQUEST">
But this type instead of giving me the actual string value of each key SET_NAME | SET_DESCRIPTION ... gives me something in the lines of ApiFunctions.setName | ApiFunctions.setDescription ...
Is there a way of achieving exactly the same type created by the template literal on any other way?
Thank you
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
