-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Module/class augmentation doesn't work #11406
Comments
I don't see any calls to |
More info added in the description of the problem. The |
The correct declaration looks like this: import {Observable} from 'rxjs'
declare module 'rxjs/Observable' {
interface Observable<T> {
doStuff():void;
}
} import { Observable, Subscription } from 'rxjs'
export class Consumer{
private _sub:Subscription;
constructor(){
this._sub = Observable.from([1,2,3]).subscribe();
Observable.from([1, 2]).doStuff(); // OK
}
} |
Yep, that works. Thanks. |
The example is just supposed to be an example and it doesn't mention rxjs at all. Do we need to use class names that no one has ever used before? |
Haha, no of course not. Just saying you've picked a name of a very popular and extendable class of a very well known library. I bet I'm not going to be the only one being thrown off by that example. |
my bad. that example was actually modeled after RXJS code a la: https://github.com/ReactiveX/rxjs/blob/master/src/add/operator/map.ts. in hind sight, probably not the best example for the general public. |
No worries. It would probably be much useful to show how to augment an external module, may that be ''rxjs'' or a fictive one. I had never seen a module declaration like that. The augmentation seems inconsistent with the way module externals are being used regularly. Is that because the ''Observable'' is being re-exported by the lib's main module? Aren't we tying ourselves up with the inner structure of the external module? |
Correct. It's tricky because it's not apparent that augmenting an alias should effect the underlying thing (what if it was aliased under a completely different name?). But this is how the runtime generally has to operate as well for augmentation -- if you're not setting on the correct root object, it may not work. |
I undestand now. Obviously not a vey sustainable solution long term. The runtime could be helped through a keyword acting as a hint that an augmentation is at play, which means the root needs to be resolved and changed? |
TypeScript Version: 2.0.3
Code
Expected behavior:
The
doStuff
to appear available in the rxjs module on theObservable
class.Actual behavior:
Attempting to use
import {Observable} from 'rxjs'
in another file (consumer.ts) causes compilation errors.Export declaration conflicts with exported declaration of 'Observable'
Property 'subscribe' does not exist on type 'Observable'
etc.
The text was updated successfully, but these errors were encountered: