0

file1.ts

namespace test { export class AA {} } 

file2.ts

/// <reference path="file1.ts" /> import * as express from "express"; // without this line it works namespace test { export class BB { constructor(a:AA){ var r = express.Router(); ... } } } 

If I comment the import line above, the code compiles but express import is missing. If I keep the import, I get

enter code hereerror TS2304: Cannot find name 'AA' 

Any idea how to fix this?

0

1 Answer 1

1

You are mixing so-called "internal" and "external" typescript modules (http://www.typescriptlang.org/Handbook#modules).

"import" keywoard tells compiler that you are using "external" approach. In this case

file1.ts - exports something

module test { export class AA {} } export = test; 

file2.ts - imports your test module

import * as express from "express"; // without this line it works import { AA } from "test" module test { export class BB { constructor(a:AA){ var r = express.Router(); ... } } } 

Update 1

This works for me in VS2015:

file "test.ts":

namespace test { export class AA { prop: string; } } export = test; 

file "consumer.ts":

import { AA } from "test"; namespace test { export class BB { constructor(a: AA) { a.prop = "some val"; } } } 
Sign up to request clarification or add additional context in comments.

3 Comments

I just updated my question, I actually ment to use namespace instead of internal modules, sorry for the confusion, any idea how to fix this?
Can you try "export = test.AA;" in the first file and 'import AA from "test";' in the second one?
Thanks TSV, Here is the result: export = test.AA; fails as test is not a module

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.