I have a JavaScript library that needs to export various constants for users who are working with vscode or TypeScript. The goal is to enable auto-complete functionality for specific constant options.
So far, I've attempted to export a Constant in the index.d.ts
file using an interface and different option types, but unfortunately, it hasn't been successful. How can I make this work?
index.d.ts
type ColorOption =
| "blue"
| "green"
| "red"
| "white"
| "gray";
interface Constant {
Colors: ColorOption;
Fonts: ...;
Icons: ...;
Spacing: ...;
}
export default Constant
The ideal scenario would be to have autocomplete suggestions like Constants.Colors.red
or Constants.Fonts.xlarge
.
EDIT:
Adding export type
seems to only work when used as a prop, such as <Component type="red" />
, whereas enums function correctly when accessed as Constants.Colors.red
. Is there a way to make both methods work seamlessly?