I am trying to create a set of static "helper" functions that I want to reuse in multiple scripts across my application. However, I run into a problem compiling because the helper functions' arguments need to be defined as types from an external module.
I have an external definition file, external.d.ts
:
declare module "external" {
export class ExternalClass { }
}
I create a set of static helper functions that I want to resuse in multiple scripts across my application, in app.helpers.ts
:
/// <reference path="external.d.ts" />
import * as external from "external";
module App {
export module Helpers {
export function helperFunction(thing: external.ExternalClass) {
//do stuff
}
}
}
Notice the function argument has a type parameter of the class from the external module definition. Now I want to use this helper function in my app.ts
:
/// <reference path="external.d.ts" />
/// <reference path="app.helpers.ts" />
import * as external from "external";
var thing: external.ExternalClass;
//instantiate thing
App.Helpers.helperFunction(thing);
However, this does not compile. On the last line, I get the error Cannot find name 'App'.
The error goes away if I comment out the import
statement in app.helpers.ts
, but then I get an error in that file Cannot find namespace 'external'.
, which is obvious because I can't reference the external module definition any more (and thus still can't compile).
I want to have a set of helper functions that I can reference via an internal module, but those functions have type parameters of types in external modules. My question is: Is there a way to make this work?