A Node.js package I'm using has a method that takes an argument required to be of a type that via IntelliSense I can see is defined with a typescript declaration in the form:
export declare type ArgType = 'A' | 'B' | 'C';
I'd like to call the package method using each permissible value for this argument in turn; in other words, something in the form:
['A','B','C'].forEach((v) => packageObject.packageMethod(v));
except I'd like to avoid hard-coding a static copy of the list of options.
If you have the ability to modify the package, you can derive the union of strings from a readonly array of string literals, and also export the array for use in runtime code:
// exported as values (usable at runtime)
export const stringArgs = ['A', 'B', 'C'] as const;
// exported as union of strings (not usable at runtime)
export type ArgType = typeof stringArgs[number]; // "A" | "B" | "C"
export function fn (arg: ArgType): void {
// ...
}
Otherwise, you'll have to parse the values using the compiler API, as mentioned by @ASDFGerte.