-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Labels
@typesRelates to working with .d.ts files (declaration/definition files) from DefinitelyTypedRelates to working with .d.ts files (declaration/definition files) from DefinitelyTypedBugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue
Milestone
Description
Using TypeScript 1.7.3.
Suppose I have the below npm packages.
The declaration files are generated by TypeScript compiler, and referred to from the other packages by means of the way described here.
package-a
ts src:
export default class ClassA {
private foo: string;
bar: number;
}
ts declaration:
declare class ClassA {
private foo;
bar: number;
}
export default ClassA;
package-b (depends on package-a):
ts src:
import ClassA from 'package-a';
namespace ClassAFactory {
export function create(): ClassA {
return new ClassA();
}
}
export default ClassAFactory;
ts declaration:
import ClassA from 'package-a';
declare namespace ClassAFactory {
function create(): ClassA;
}
export default ClassAFactory;
package-c (depends on package-a and package-b):
ts src:
import ClassA from 'package-a';
import ClassAFactory from 'package-b';
let classA: ClassA;
classA = ClassAFactory.create(); // error!!
The last line causes an error during compilation:
error TS2322: Type 'ClassA' is not assignable to type 'ClassA'.
Types have separate declarations of a private property 'foo'.
When I remove the line private foo;
from the declaration of package-a, TypeScript does not emit any error.
However this workaround is a bit painful.
I understand that exposing private properties to declaration is by design (#1532).
I think TypeScript should ignore private properties when compiling variable assignment.
Or is there any better workaround for this?
wabson, valente, bahodirk, jsplink, giovannicandido and 37 more
Metadata
Metadata
Assignees
Labels
@typesRelates to working with .d.ts files (declaration/definition files) from DefinitelyTypedRelates to working with .d.ts files (declaration/definition files) from DefinitelyTypedBugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue