question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error in project with TS 2.6 and strictFunctionTypes

See original GitHub issue

RxJS version: 5.5.2

Code to reproduce:

In tsconfig.json:

{
  "compilerOptions": {
    "skipLibCheck": false,
    "strictFunctionTypes": true
  }
}
import * as Rx from "rxjs";

Expected behavior:

Compiles successfully.

Actual behavior:

Compiler error:

../../node_modules/rxjs/scheduler/VirtualTimeScheduler.d.ts(22,22): error TS2415: Class 'VirtualAction<T>' incorrectly extends base class 'AsyncAction<T>'.
  Types of property 'work' are incompatible.
    Type '(this: VirtualAction<T>, state?: T | undefined) => void' is not assignable to type '(this: AsyncAction<T>, state?: T | undefined) => void'.
      The 'this' types of each signature are incompatible.
        Type 'AsyncAction<T>' is not assignable to type 'VirtualAction<T>'.
          Property 'index' is missing in type 'AsyncAction<T>'

Additional information:

Workaround: disable strictFunctionTypes OR enable skipLibCheck

I believe this is happening because work is not defined as a method (rather, it’s defined as a property), so its parameters are checked contravariantly. If it was defined as a method, the parameters would be checked covariantly.

This could be fixed by defining work as a method in both classes, or defining it as (this: AsyncAction<T>, state?: T) => void in VirtualAction.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:79
  • Comments:19 (1 by maintainers)

github_iconTop GitHub Comments

9reactions
craftytrickstercommented, Jan 30, 2018

To workaround this issue, you need, "skipLibCheck": true, not false. In generally, I would say it is bad practice to skipLibCheck, but since RxJs typings are broken, it is the only way around the issue.

3reactions
colindekkercommented, Feb 3, 2018

The issue in the VirtualTimeScheduler.d.ts file is there with TS 2…7.1 too. Changing the type if the this parameter of the work method from VirtualAction to its basetype AsyncAction in the VirtualTimeScheduler.d.ts file fixes the build issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - TypeScript 2.6
Intuitively, the default mode permits the assignment because it is possibly sound, whereas strict function types mode makes it an error because it...
Read more >
Announcing TypeScript 2.6 RC - Microsoft Developer Blogs
Under --strictFunctionTypes , any function type that doesn't originate from a method has its parameters compared contravariantly. That means ...
Read more >
typescript suppress error, ts-ignore not working, tsconfig ...
typescript suppress error. This feature is called "strict null checks", to turn it off ensure that the --strictNullChecks compiler flag is not set....
Read more >
error "Unknown compiler option 'strictFunctionTypes...
I want to create a POS project. when making extension project ... I get an error titled "Unknown compiler option 'strictFunctionTypes' .
Read more >
How TypeScript's Strict Mode Actually Fixes TypeScript
You can disable any option that you don't like from the strict ... now fix this in TypeScript 2.6 with --strictFunctionTypes or --strict...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found