rxjs: Error in project with TS 2.6 and strictFunctionTypes
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
.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 79
- Comments: 19 (1 by maintainers)
Commits related to this issue
- build: restore build working around RxJS type bug More at: https://github.com/ReactiveX/rxjs/issues/3031 — committed to deanrad/antares-ts by deanius 6 years ago
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.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 fromVirtualAction
to its basetypeAsyncAction
in the VirtualTimeScheduler.d.ts file fixes the build issue.As @colindekker said - the best way is to change the
work
method parameter toAsyncAction
- this will skip the linter error / build error. From my point of view this is one of the best solutions for now - when the package will get updated the problem should also be solved and updated. Since the error is minor.