I'm trying to create TypeScript definition files for a library.
The library has a method that accepts a parameter of type number, but that parameter can only be a certain set of numbers, so I want to have my definition say it requires an enum type that I created using a const enum.
However, when I define my class in a .d.ts, like so:
// definitions/SimpleDefinition.d.ts
/// <reference path="Enums.ts" />
declare class SampleDefinedClass {
public static SampleMethod(enumArg: Enums.SampleEnum): void;
}
My enum like this:
// definitions/Enums.ts
export const enum SampleEnum {
Item1 = 1,
Item2 = 2
}
And I have an index.d.ts to tie the 2 together:
// definitions/index.d.ts
/// <reference path="Enums.ts" />
/// <reference path="SampleDefinition.d.ts" />
The compiler tells me this:
../definitions/SampleDefinition.d.ts(4,41): error TS2503: Cannot find namespace 'Enums'.
I have tried adding an import to the top of my SampleDefinition.d.ts, but that resulted in the definition not being properly recognized in my code file. Though Visual Studio and Visual Studio code won't show an error on the actual import.
import Enums = require("./Enums");
Main.ts(6,1): error TS2304: Cannot find name 'SampleDefinedClass'.
I have tried several more thing, like using AMD, and moving files around, but can't seem to get this to work. Is there a way to do this? Or will I have to find another way to do it/give up?
I've created a GitHub repo with this exact sample.