I am using typescript with atom version 1.7.5
I have a declaration file Provision.d.ts with the following declarations
declare module Provision {
export enum ProvisionMode {
NOOP,
PRODUCTION,
DEVELOPMENT,
TEST,
DEFAULT
}
export interface ProvisionSettingsService {
setGlobalProvisionMode(arg0: ProvisionMode, arg1: string, back: Http.HttpDefaultCallback): void;
getGlobalProvisionMode(arg0: string, back: Http.HttpDefaultCallback): void;
setPathProvision(arg0: string, arg1: ProvisionMode, back: Http.HttpDefaultCallback): void;
getPathProvision(arg0: string, back: Http.HttpDefaultCallback): void;
}
}
and then my implementation file Provision.ts
/// <reference path='./Provision.d.ts'/>
module ProvisionImpl{
export class ProvisionServiceCallback implements Http.Callback<Provision.ProvisionMode>{
onSuccess(data: Provision.ProvisionMode): void {
}
onError(): void {
var console: Console;
console.log("provision callback Error");
}
}
export class ProvisionServiceClient implements Provision.ProvisionSettingsService{
setGlobalProvisionMode(arg0: Provision.ProvisionMode, arg1: string, back : Http.HttpDefaultCallback): void{
/// ..... various implementations here
}
getGlobalProvisionMode(arg0: string , back : Http.HttpDefaultCallback): void{
/// ..... various implementations here
}
setPathProvision(arg0: string, arg1: Provision.ProvisionMode, back : Http.HttpDefaultCallback): void{
/// ..... various implementations here
}
getPathProvision(arg0: string, back : Http.HttpDefaultCallback): void{
/// ..... various implementations here
}
}
}
When I try to use the above implementation in my code say CountryService.ts
/// <reference path='./Provision.d.ts' />
/// <reference path='./Provision.ts' />
class App{
public switchOp() {
var client = new ProvisionImpl.ProvisionServiceClient();
var noop = Provision.ProvisionMode.NOOP ;
var prod = Provision.ProvisionMode.PRODUCTION ;
if (this.op){
client.setGlobalProvisionMode(noop , "dummy" , new Http.HttpDefaultCallback()) ;
}else{
client.setGlobalProvisionMode(prod , "dummy" , new Http.HttpDefaultCallback()) ;
}
}
}
new App().switchOp();
Though my code compiles without any complaint it consistently gives me an error
Uncaught ReferenceError: Provision is not defined
on this line
var noop = Provision.ProvisionMode.NOOP ;
export module, check the javascript generated.. is it creating a variable namedProvisionand creating the enum on that variable??*.d.ts) are mainly meant to declare things that exist in your JS, not actually supply them. Change it to a.tssource file and I believe it will work.