-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Open
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: Declaration EmitThe issue relates to the emission of d.ts filesThe issue relates to the emission of d.ts files
Milestone
Description
TypeScript Version: 2.4.2
Code:
I'm using mixins as described by: #13743
export type Constructor<T> = new(...args: any[]) => T;
export function Unsubscriber<T extends Constructor<{}>>(Base: T) {
class Unsubscriber extends Base implements OnDestroy {
protected unsubscribe: Subject<void> = new Subject();
ngOnDestroy() {
this.unsubscribe.next();
this.unsubscribe.complete();
}
}
return Unsubscriber;
}
If I compile this code with "declaration": true
to get type definitions for my library, I get the following error:
ERROR in (truncated)/mixins.ts (...): Return type of exported function has or is using private name 'Unsubscriber'.
One solution is to add an interface...
export interface IUnsubscriber extends OnDestroy {
unsubscribe: Subject<void>;
}
...and have my mixin function
have a return type of Constructor<IUnsubscriber>
. This works, but it forces me to make the properties/methods exposed by my mixin be public
even in cases where I want them to be protected
.
Short of adding protected
members to interfaces (which I'm not sure is the right thing to do), this seems to be a limitation of the currently supported mixin strategy.
ethanresnick, mattiamanzati, caseyWebb, lmk123, mramos-dev and 46 morelkraav, SirDavidLudwig and mihaisilviupop
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: Declaration EmitThe issue relates to the emission of d.ts filesThe issue relates to the emission of d.ts files