Skip to content

External modules that don't export anything emit empty declarations. #6022

@robwormald

Description

@robwormald

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));
}
//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":

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

CC @Blesh @jeffbcross

RxJS Issue: ReactiveX/rxjs#1010
Sample file: https://github.com/ReactiveX/RxJS/blob/master/src/add/operator/map.ts

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issue

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions