In Typescript, how do you export concrete string enums in your module typing definitions?

285 views Asked by At

I want to provide typings for my module. The interface for my module requires string enums for certain parameters. Crucially, these parameters must be actual strings which do not disappear when you compile. That means enum, not const enum.

There is an example here:
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/nodegit/enums.d.ts

Usage here:
https://github.com/DefinitelyTyped/DefinitelyTyped/search?q=enums.d.ts&unscoped_q=enums.d.ts

of how one might define and export const string enums. However, this doesn't work if you remove the const.

I've tried all kinds of approaches, but I can't provide concrete string enums with my module.

The work around I can think of is to define a type which is allowed to be the various strings and define string constants for the user's convenience, however it requires double-defining all the available values.

0

There are 0 answers