I'm trying to find a method similar to keyof typeof myModule
in typescript. However, instead of a union of key strings, I need a union of the value types.
I have a module with an increasing number of exports -
myModule.ts:
export const Thing1;
export const Thing2;
export const Thing3;
// ... many more things!
This module is imported elsewhere, and I want to create a union type that is Thing1 | Thing2 | Thing3 | ...
, without having to do it manually.
anotherModule.ts:
import * as things from './myModule';
type AnyThingKey = keyof typeof things;
function useThings(thing: /* AnyThing - this is where/how I'd use the union type */) {
// ... do things ...
}
Is there a standard way to achieve this?