TypeScript: imported module classes are not visible -



TypeScript: imported module classes are not visible -

i testing typescript compiler multiple modules compiled amd modules.

i have module "test" , separate file utilize it

test.ts:

export module test { 'use strict'; export class person { age:number = 0; sin:number = 1; } var pp = new person(); }

test.ts declares module "test" , exports it. file compiles , js out set expected:

test.js:

define(["require", "exports"], function(require, exports) { (function (test) { 'use strict'; var person = (function () { function person() { this.age = 0; this.sin = 1; } homecoming person; })(); test.person = person; var pp = new person(); })(exports.test || (exports.test = {})); var test = exports.test; })

now in same folder there test2.ts using module "test"

test2.ts:

///<reference path="test.ts"/> import tt = module("test"); var p = tt.person;

the compiler complains here:

src/ts/test2.ts(5,11): property 'person' not exist on value of type 'tt'

the output js file seems right though: test2.js:

define(["require", "exports", "test"], function(require, exports, __tt__) { ///<reference path="test.ts"/> var tt = __tt__; var p = tt.person; })

the compiler version is:

0.8.2.0

command line is:

tsc --comments --declaration --target es5 --module amd $filepath$

what problem compiler here?

thanks.

here code need...

import tt = module("test"); var p = new tt.test.person();

and quick explanation.

when using amd or commonjs load modules , using import statements, don't need utilize reference comments. import need.

also, file module, tt in code represents test.ts. within of file (which module) module explicitly called test, in fact have construction this: test.test.person.

you opt utilize file module , not add together nested one, this:

test.ts

export class person { age:number = 0; sin:number = 1; } var pp = new person();

this allow utilize non-nested version, is:

import tt = module("test"); var p = new tt.person();

typescript

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -