Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define and consume enums in typescript when using AMD?

Tags:

typescript

amd

The following tsc command doesn't create a usable foo.d.ts:

TSC -declaration -m amd foo.ts 

foo.ts:

export enum foo {
    bar
}

foo.d.ts:

export declare enum foo {
    bar,
}

But

///<reference path="./foo.d.ts"/> 

doesn't work until the "export" is removed fro foo.d.ts. Is there another way of declaring a variable of type foo in a second file? Seems to me referencing foo.ts should have worked (it didn't):

///<reference path="./foo.ts"/> 

Am I missing a keyword?

like image 991
Corey Alix Avatar asked Oct 21 '22 00:10

Corey Alix


1 Answers

When you are working with external modules in TypeScript ///<reference comments are not relevant.

To import the type into another file you need to do:

import mod = require('./foo'); 
// Then access the enum object as : mod.foo

To learn about internal vs. external modules check out this short video tutorial I made : http://www.youtube.com/watch?v=KDrWLMUY0R0&hd=1

like image 142
basarat Avatar answered Oct 24 '22 04:10

basarat