Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import enum in interface declaration file (d.ts)

I want to extend string with a method that needs an enumeration to be passed. How do I import that enum into the declaration file?

CapitalizationStyle.tsx:

export enum CapitalizationStyle {
    None = 0,
    Lowercase = 1,
    Word = 2
}

StringExtensions.d.ts:

import { CapitalizationStyle } from "Utils/CapitalizationStyle"; //This line breaks everything.

declare interface String {
    applyCapitalizationStyle(this: string, style: CapitalizationStyle): string;
}

The import breaks the interface declaration, like if the declaration does not exist anymore. All extension implementations of the String class become invalid as soon as I add the import:

StringExtensions.tsx:

enter image description here

Minimal reproducible example project: https://wetransfer.com/downloads/d1a707c0ac734985b877058967c35a6820171212143715/410f48

like image 945
olivierr91 Avatar asked Aug 31 '25 03:08

olivierr91


1 Answers

Since you don't have a default export from that module, you need to wrap it in {}:

import { CapitalizationStyle } from "Utils/CapitalizationStyle";
like image 181
msanford Avatar answered Sep 02 '25 16:09

msanford