Skip to content

Issue with module augmentation defined in another (symlinked) package #17450

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

Closed
QuentinFchx opened this issue Jul 27, 2017 · 1 comment
Closed

Comments

@QuentinFchx
Copy link

TypeScript Version: 2.4.2

Code

// RxPlus.ts   # npm package containing this augmentation (of rxjs), and symlinked (under "shared" name)
import { Observable } from 'rxjs';

declare module 'rxjs/Observable' {
    interface Observable<T> {
        parseInt(): Observable<number>;
    }
}

Observable.prototype.parseInt = function (this: Observable<any>) {
    return this.map(res => parseInt(res, 10));
};
// main.ts   # usage of the augmentation in another package
import 'shared/RxPlus';
import { Observable } from 'rxjs';

Observable.from([1, 2]).parseInt();
// error TS2339: Property 'parseInt' does not exist on type 'Observable<number>'.

However, the above works if the augmentation is defined in the same package than main.ts

I also did a small repro project highlighting the error.

I tried adding a declaration file to the external package, without success (I might have declared it poorly though)

It might relate to/duplicate #11406 and #12607. Also I think this stackoverflow question describes the same case (but unfortunately no answers)

Expected behavior:
A module augmentation defined in an external (symlinked) package should be working when imported into another package

Actual behavior:
The compiler is unaware of an augmentation defined in an external (symlinked) package

@QuentinFchx
Copy link
Author

QuentinFchx commented Aug 3, 2017

I tried to investigate a bit more: it really seems to be caused by symlinking (npm link)

On the repro project I linked above, if I copy the shared module into project/node_modules (to simulate a "true" external package, not symlinked) it works...

I added instructions on my repository. I'm sorry to insist, but can anyone just take a look at the reproduction repo and confirm or not the issue? I tried to make it small and easy to setup. 😇

Edit: Also the reason I need symlinks is because I'm using lerna

Edit2: Or is it an issue with npm link/install not flattening the dependencies tree? Leading to having rxjs (in my case) "installed" twice? Thus confusing typescript?

Edit3: It seems that #11916 (comment) solved the issue.

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant