Error in project with TS 2.6 and strictFunctionTypes
See original GitHub issueRxJS 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:
- Created 6 years ago
- Reactions:79
- Comments:19 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.