Struggling to generate TypeScript definition files for a specific library.
The library contains a method that requires a parameter of type number
, limited to a specific set of numbers. Therefore, I aim to specify in my definition that it necessitates an enum type created using a const enum
.
However, upon defining my class within a .d.ts
file like this:
// definitions/SimpleDefinition.d.ts
/// <reference path="Enums.ts" />
declare class SampleDefinedClass {
public static SampleMethod(enumArg: Enums.SampleEnum): void;
}
I define my enum as follows:
// definitions/Enums.ts
export const enum SampleEnum {
Item1 = 1,
Item2 = 2
}
To link the two, I utilize an index.d.ts
:
// definitions/index.d.ts
/// <reference path="Enums.ts" />
/// <reference path="SampleDefinition.d.ts" />
The compiler throws this error message:
../definitions/SampleDefinition.d.ts(4,41): error TS2503: Cannot find namespace 'Enums'.
I attempted adding an import statement at the beginning of my SampleDefinition.d.ts
, but this led to the definition not being correctly identified in my code file, despite no errors shown by Visual Studio or Visual Studio Code for the import itself.
import Enums = require("./Enums");
Main.ts(6,1): error TS2304: Cannot find name 'SampleDefinedClass'.
Various attempts have been made, such as experimenting with AMD and relocating files, yet achieving functionality seems elusive. Is there a viable solution? Or must I resort to alternative methods or abandon the endeavor?
A Github repository showcasing this scenario can be found here.