-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Description
Background - in RxJS we have a number of "operators" that extend our base Observable type.
//src/Observable.ts
class Observable {
map: <R>(project: (x: T, ix?: number) => R, thisArg?: any) => Observable<R>;
}// src/operators/map.ts
export function map<T, R>(project: (x: T, ix?: number) => R, thisArg?: any): Observable<R> {
if (typeof project !== 'function') {
throw new TypeError('argument is not a function. Are you looking for `mapTo()`?');
}
return this.lift(new MapOperator(project, thisArg));
}
//snipThis separation allows a user to import the map operator function and use it without bringing in the other 95 or so - without "side-effects":
import {map} from 'rxjs/operators/map'
map.call(someObservable, (v) => v + 1 );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:
//rxjs/add/operators/map.ts
import {Observable} from '../../Observable';
import {map} from '../../operator/map';
Observable.prototype.map = map;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.
Discussed with @mhegazy
RxJS Issue: ReactiveX/rxjs#1010
Sample file: https://github.com/ReactiveX/RxJS/blob/master/src/add/operator/map.ts