Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript error in config.ts: Conversion of type 'undefined' to type 'PromiseConstructorLike' may be a mistake #5025

Closed
kostrse opened this issue Sep 19, 2019 · 3 comments

Comments

@kostrse
Copy link

kostrse commented Sep 19, 2019

RxJS: 6.5.3
TS: 3.6.2

src/internal/config.ts

export const config = {
  /**
   * The promise constructor used by default for methods such as
   * {@link toPromise} and {@link forEach}
   */
  Promise: undefined as PromiseConstructorLike,

Fails with compilation error:

TypeScript error in D:/Dev/OpDashBoard/FrontEnd/ClientApp/node_modules/rxjs/src/internal/config.ts(12,12):
Conversion of type 'undefined' to type 'PromiseConstructorLike' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. TS2352

I think the fix would be to define it as:

  Promise: undefined as unknown as PromiseConstructorLike

Or maybe another, cleaner way.

Repro in Playground

@kostrse
Copy link
Author

kostrse commented Sep 19, 2019

I got this error when accidentally imported a RxJS file under src/internal/ into my project

@cartant
Copy link
Collaborator

cartant commented Sep 19, 2019

In the interim, you could - should, IMO - specify skipLibCheck in the compiler options in your tsconfig.json. There really is little point in having TypeScript check the internals of packages within node_modules when those packages contains .d.ts files that have already passed through the TypeScript compiler.

Ah, never mind - I just read your second comment.

@cartant
Copy link
Collaborator

cartant commented Oct 12, 2019

I'm going to close this as it's a sub-case of a known issue: the TypeScript compiler options used to build RxJS are insufficiently strict. In particular, strictNullChecks is false. See #4968

@cartant cartant closed this as completed Oct 12, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Nov 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants