Rxjs: Type definition complains

Created on 23 Oct 2015  路  13Comments  路  Source: ReactiveX/rxjs

I am trying to transpile the following helloworld.ts file:

import Rx = require("@reactivex/rxjs");
Rx.Observable.of('Hello World!').subscribe(function(value) {
console.log(value);
});

I have TypeScript 1.6.2 installed and have installed:
npm install @reactivex/rxjs

I am receiving the following errors, am I doing something wrong or this is a bug:

tsc -module commonjs helloworld
node_modules/@reactivex/rxjs/dist/cjs/CoreOperators.d.ts(21,70): error TS2304: Cannot find name 'Promise'.
node_modules/@reactivex/rxjs/dist/cjs/CoreOperators.d.ts(73,31): error TS2304: Cannot find name 'PromiseConstructor'.
node_modules/@reactivex/rxjs/dist/cjs/CoreOperators.d.ts(73,54): error TS2304: Cannot find name 'Promise'.
node_modules/@reactivex/rxjs/dist/cjs/Observable.d.ts(63,53): error TS2304: Cannot find name 'PromiseConstructor'.
node_modules/@reactivex/rxjs/dist/cjs/Observable.d.ts(63,74): error TS2304: Cannot find name 'Promise'.
node_modules/@reactivex/rxjs/dist/cjs/Observable.d.ts(74,38): error TS2304: Cannot find name 'Promise'.
node_modules/@reactivex/rxjs/dist/cjs/Observable.d.ts(97,69): error TS2304: Cannot find name 'Promise'.
node_modules/@reactivex/rxjs/dist/cjs/Observable.d.ts(149,30): error TS2304: Cannot find name 'PromiseConstructor'.
node_modules/@reactivex/rxjs/dist/cjs/Observable.d.ts(149,53): error TS2304: Cannot find name 'Promise'.

Most helpful comment

also note that TS includes the types that are erroring in https://github.com/Microsoft/TypeScript/blob/master/lib/lib.es6.d.ts#L5095

So, if you're targeting ES5/CJS, you can simply add that file to your tsconfig:

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es5",
        "noImplicitAny": false,
        "outDir": "built",
        "rootDir": ".",
        "sourceMap": false
    },
    "files": [
      "helloworld.ts",
      "node_modules/typescript/lib/lib.es6.d.ts"
    ],
    "exclude": [
        "node_modules"
    ]
}

and run tsc at the prompt. no errors, no silly /// refs.

All 13 comments

You're missing type definition declaration for promise.

///<reference path="...../fileforpromisedefinition.d.ts" />

either you can manually pick those definition, or could lookup definitelytyped.

In my case, I use es6-promise for testing codes.

After adding the es6-promise it is still giving the following errors:

node_modules/@reactivex/rxjs/dist/cjs/CoreOperators.d.ts(73,31): error TS2304: Cannot find name 'PromiseConstructor'.
node_modules/@reactivex/rxjs/dist/cjs/Observable.d.ts(63,53): error TS2304: Cannot find name 'PromiseConstructor'.
node_modules/@reactivex/rxjs/dist/cjs/Observable.d.ts(149,30): error TS2304: Cannot find name 'PromiseConstructor'.

Installed and this works:
tsd init
tsd install es6-shim --save

And adding this in the helloworld.ts:
///

Thanks

Think this can be closed?

Yes thanks, however I think this is a bug because es6-shim is already included here:

https://github.com/ReactiveX/RxJS/blob/master/tsd.json

Adding it ourselves should not be required.

Meaning packaging type definition (d.ts) into npm package by default?

@robwormald have you run into this?

yep, but we include es6-shim in the angular repo (temporarily) so this error doesn't surface for us.

I'll have a proper look tomorrow, we're doing a bit of hackery to make this work correctly.

also note that TS includes the types that are erroring in https://github.com/Microsoft/TypeScript/blob/master/lib/lib.es6.d.ts#L5095

So, if you're targeting ES5/CJS, you can simply add that file to your tsconfig:

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es5",
        "noImplicitAny": false,
        "outDir": "built",
        "rootDir": ".",
        "sourceMap": false
    },
    "files": [
      "helloworld.ts",
      "node_modules/typescript/lib/lib.es6.d.ts"
    ],
    "exclude": [
        "node_modules"
    ]
}

and run tsc at the prompt. no errors, no silly /// refs.

@ziaukhan @robwormald has this been resolved?

I'd like to suggest to close this for now - remaining discussion in here is if RxJS need to package type definition of es6-shim or not. As @robwormald suggested, lib.es6.d.ts can be used.

That sounds reasonable. We can always reopen.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

giovannicandido picture giovannicandido  路  4Comments

samherrmann picture samherrmann  路  3Comments

unao picture unao  路  4Comments

cartant picture cartant  路  3Comments

jakovljevic-mladen picture jakovljevic-mladen  路  3Comments