Rxjs: error TS2585: 'Promise' only refers to a type, but is being used as a value here. Do you need to change your target library? Try changing the `lib` compiler option to es2015 or later.

Created on 3 Jan 2019  路  11Comments  路  Source: ReactiveX/rxjs

Bug Report

error TS2585: 'Promise' only refers to a type, but is being used as a value here. Do you need to change your target library? Try changing the lib compiler option to es2015 or later.

Current Behavior

node_modules/rxjs/internal/Observable.d.ts:82:59 - error TS2585: 'Promise' only refers to a type, but is being used as a value here. Do you need to change your target library? Try changing the `lib` compiler option to es2015 or later.                                                                   

82     toPromise<T>(this: Observable<T>, PromiseCtor: typeof Promise): Promise<T>;                                                                    
                                                             ~~~~~~~


Found 1 error.

Reproduction

  • REPL or Repo link:

https://stackoverflow.com/questions/54014405/ts2585-promise-only-refers-to-a-type-but-is-being-used-as-a-value-here?noredirect=1#comment94866023_54014405

Environment

  • Runtime: Node 11.6
  • RxJS version: 6.3.3

see https://stackoverflow.com/questions/54014405/ts2585-promise-only-refers-to-a-type-but-is-being-used-as-a-value-here?noredirect=1#comment94866023_54014405

needs info

Most helpful comment

Whelp, it is. I'll file the bug in TypeScript.

All 11 comments

If you are targeting an earlier version of JS, you will need a Promise polyfill. That's the source of the problem. RxJS does not include such a polyfill, so the Promise constructor does not exist and the error you reported is effected.

I'm not targeting an earlier version of JS (or trying to anyway), I'm just trying to get things working for node v11.6 which is the newest.

You should include a minimal repro with the exact settings that see the error effected. The SO question includes more than one set of tsconfig.json properties. TBH, if this is an issue at all, it looks like a TS issue and not an RxJS issue.

Not sure where the complexity is (the se had the conf and the code) but I'm happy to do it.

https://github.com/EvanCarroll/rxjsissue4448

@kwonoj @cartant

Now remove RxJS from your minimal repro and add the following instead:

type P = typeof Promise;

If the error is still effected, you can close this and report it in the TypeScript repo, instead.

Whelp, it is. I'll file the bug in TypeScript.

@cartant bug found tsc file.ts does not process typescript.conf

Yeah, that rings a bell. I think I've been bitten by that behaviour in the past.

So what was the conclusion here? I'm getting the same error - followed here from stack overflow

@reed-lawrence The conclusion is that this is - as discussed above - not an RxJS issue.

Was this page helpful?
0 / 5 - 0 ratings