You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
External modules that don't export anything emit empty declarations. #6022
// src/operators/map.tsexportfunctionmap<T,R>(project: (x: T,ix?: number)=>R,thisArg?: any): Observable<R>{if(typeofproject!=='function'){thrownewTypeError('argument is not a function. Are you looking for `mapTo()`?');}returnthis.lift(newMapOperator(project,thisArg));}//snip
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 the map 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 to import 'rxjs/add/operators/map.ts', the Typescript compiler errors with
error TS2656:
Exported external package typings file 'node_modules/rxjs/add/operator/map.d.ts' is not a module.
Please contact the package author to update the package definition.
// b.ts
import {A} from './a';
// do some prototype patching or other side effect stuff here
With the declaration option set to true, the declaration file for b.ts is still generated empty, which makes it impossible to import it for consumers of the library. I'm not sure there's anything that needs to be changed in what is generated, but possibly the error for importing an empty declaration file for its side effects should be removed.
you need to declare module augmentation for ./a in b.ts in order to explicitly tell compiler that this is module is patching its imports (or global scope). In this case compiler will keep treat this file as internal module.
Vladimir Matveev (@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:
import {Observable} from '../../Observable';
import {DeferObservable} from '../../observable/DeferObservable';
Observable.defer = DeferObservable.create;
// export var _void: void; // This is a workaround the RxJS team added
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?
import {Observable} from '../../Observable';
import {DeferObservable} from '../../observable/DeferObservable';
Observable.defer = DeferObservable.create;
declare module '../../Observable' { } // Dummy module augmentation to ensure the definition file is not empty
I'm curious if we can just add export {} when emitting declaration file for an external module that does not export anything by itself (just to preserve the fact that original file is external module so it should be ok to import it). pinging Mohamed Hegazy (@mhegazy)Anders Hejlsberg (@ahejlsberg) for their opinion.
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).
The error (which is identical to the error at the top of this issue) is:
ts/main.ts(1,8): error TS2656: Exported external package typings file 'E:/depot/untracked/test/node_modules/rxjs/add/observable/fromArray.d.ts' is not a module. Please contact the package author to update the package definition.
The corresponding fromArray.d.ts file is empty.
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.
Asad Saeeduddin (@masaeedu) can you give typescript@next a try later tonight, and let us know if this scenario is working end-to-end or you are still running into issue.
Activity
vladima commentedon Jan 16, 2016
fixed in #6213
masaeedu commentedon Feb 2, 2016
Vladimir Matveev (@vladima) I'm still seeing this issue. When doing:
With the
declarationoption set totrue, the declaration file forb.tsis still generated empty, which makes it impossible to import it for consumers of the library. I'm not sure there's anything that needs to be changed in what is generated, but possibly the error for importing an empty declaration file for its side effects should be removed.vladima commentedon Feb 2, 2016
you need to declare module augmentation for
./ainb.tsin order to explicitly tell compiler that this is module is patching its imports (or global scope). In this case compiler will keep treat this file as internal module.Output after running
node built/local/tsc.js b.ts -m commonjs -d:masaeedu commentedon Feb 2, 2016
Vladimir Matveev (@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.
masaeedu commentedon Feb 2, 2016
Would you recommend adding an empty module declaration for every such file?
vladima commentedon Feb 2, 2016
I'm curious if we can just add
export {}when emitting declaration file for an external module that does not export anything by itself (just to preserve the fact that original file is external module so it should be ok to import it). pinging Mohamed Hegazy (@mhegazy) Anders Hejlsberg (@ahejlsberg) for their opinion.masaeedu commentedon Feb 2, 2016
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).
mhegazy commentedon Feb 2, 2016
Asad Saeeduddin (@masaeedu) i do not see how you are getting any errors here. here is the setup that i have:
generates:
now we use it in anohter module
Can you give us more information on where you are seeing the error/
masaeedu commentedon Feb 2, 2016
Mohamed Hegazy (@mhegazy) Here's what I'm seeing:
The error (which is identical to the error at the top of this issue) is:
The corresponding
fromArray.d.tsfile is empty.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.
mhegazy commentedon Feb 2, 2016
aah.. that is a different one, thanks for the info. i think we should relax this check, the error here is not meaningful.
vladima commentedon Feb 2, 2016
#6846 should cover this
mhegazy commentedon Feb 2, 2016
Asad Saeeduddin (@masaeedu) can you give
typescript@nexta try later tonight, and let us know if this scenario is working end-to-end or you are still running into issue.masaeedu commentedon Feb 2, 2016
Mohamed Hegazy (@mhegazy) Will do
masaeedu commentedon Feb 3, 2016
Mohamed Hegazy (@mhegazy) Looks like it works 👍
benlesh commentedon Feb 3, 2016
I know this isn't a helpful comment: But I'm super pleased with the work being done here. Thanks everyone.