-
Notifications
You must be signed in to change notification settings - Fork 12.8k
External modules that don't export anything emit empty declarations. #6022
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
Comments
fixed in #6213 |
@vladima I'm still seeing this issue. When doing:
With the |
you need to declare module augmentation for // a.ts
export class A {} // b/ts
import {A} from "./a";
(<any>A.prototype).foo = function() {}
declare module "./a" {} Output after running // b.d.ts
declare module "./a" {
}
export {}; // still an external module |
@vladima Some modules don't have any type signatures to merge. They simply mutate existing members. A good example is this file, which assigns a function to a static class member declared elsewhere:
The .d.ts file generated for this is empty, which means consumers of the compiled JS + definitions will get an error when trying to import it, although within the TypeScript codebase it is treated as an external module and can be imported without problems. |
Would you recommend adding an empty module declaration for every such file?
|
I'm curious if we can just add |
Another alternative would be to not emit anything instead of emitting an empty file, since this also eliminates the error (although this might come with its own set of problems that I'm not foreseeing). |
@masaeedu i do not see how you are getting any errors here. here is the setup that i have: // deferedAugmentation.ts
import {Observable} from '../../Observable';
import {DeferObservable} from '../../observable/DeferObservable';
Observable.defer = DeferObservable.create; generates: // deferedAugmentation.d.ts
// Empty now we use it in anohter module // anotherModule.ts
import "./deferedAugmentation"; // No Error Can you give us more information on where you are seeing the error/ |
@mhegazy Here's what I'm seeing: The error (which is identical to the error at the top of this issue) is:
The corresponding Maybe this occurs only when importing a typings file from a node module? I'm not sure what the actual cause is, so I'm still trying to figure out a way to set up a simplified testcase for you. |
aah.. that is a different one, thanks for the info. i think we should relax this check, the error here is not meaningful. |
#6846 should cover this |
@masaeedu can you give |
@mhegazy Will do |
@mhegazy Looks like it works 👍 |
I know this isn't a helpful comment: But I'm super pleased with the work being done here. Thanks everyone. |
Background - in RxJS we have a number of "operators" that extend our base Observable type.
This separation allows a user to import the
map
operator function and use it without bringing in the other 95 or so - without "side-effects":Without functionBind, this is slightly unergonomic, so we defined a set of "patch" modules that import the
Observable
type and the themap
operator, and patch the prototype there:With the idea being a user should be able to simply
import 'rxjs/add/operators/map'
and have the prototype patched in the background.Issue:
The emitted
rxjs/add/operators/map.d.ts
file is emitted completely empty, and so when a user goes toimport 'rxjs/add/operators/map.ts'
, the Typescript compiler errors withDiscussed with @mhegazy
CC @Blesh @jeffbcross
RxJS Issue: ReactiveX/rxjs#1010
Sample file: https://github.com/ReactiveX/RxJS/blob/master/src/add/operator/map.ts
The text was updated successfully, but these errors were encountered: