|
|
The following scenario is currently not possible:
Implement a class Foo in Foo.ts with a reference to Bar and a class Bar in Bar.ts containing a reference to Foo. First, you will not be able to generate Foo.d.ts and Bar.d.ts automatically. If you create them manually and reference them via <reference>, you will get strange compilation issues if you want to compile them to a single file like " Malformed function body (is this a class named the same as an existing interface?).
The reason is that a .d.ts is not really a declaration. It is already a definition. The smallest repo of this issue is referencing Foo.d.ts in Foo.ts which causes the same error as above. Although this not really a use case, the above example with Foo and Bar is quite frequent.
.d.ts files should either behave like C/C++ headers or there should be no .d.ts files at all (as in Java or C#).
|
|
Coordinator
Feb 1 at 3:11 PM
|
I'm trying this on a compiler built from the latest 'develop' branch (which will be 0.8.3 in the future). Here's my example:
Bar.ts
///<reference path="./Foo.ts"/>
class Bar {
public barField: string;
}
var foo = new Foo();
Foo.ts
///<reference path="./Bar.ts"/>
class Foo {
public fooField: number;
}
var bar = new Bar();
If I then run:
tsc --declaration Bar.ts
I get a pair of .js files for each .ts file and two declarations files to go along with them, so this may have been fixed recently. If you can, I suggest trying out the latest compiler and see if you still see the issue.
|
|
|
|
I tried your example with 0.8.2 and it worked as well. Here is my example:
Bar.ts
/// <reference path="Foo.d.ts"/>
module foo {
export class Bar {
public barField: string;
}
}
Foo.ts
/// <reference path="Bar.d.ts"/>
module foo {
export class Foo {
private _bar: Bar;
constructor() {
this._bar = null;
}
};
}
Then, I do the following:
rm Bar.d.ts Foo.d.ts
tsc --declaration Bar.ts
tsc --declaration Foo.ts
tsc --declaration Foo.ts
Foo.ts(9,2): Malformed function body (is this a class named the same as an existing interface?)
|
|