We are using Knockout.js (v3.5.0) and its TypeScript definitions. They worked OK until TypeScript 4.6.2. However the problem seems to be "deeper" than in the definitions file. It seems that there was some change in TypeScript in handling a boolean type. So rather than tagging this question as Knockout.js problem, I created small example of code inspired by the Knockout d.ts that illustrates the problem:
interface Observable<T>
{
(): T;
(value: T): any;
}
function observable<T>(value: T): Observable<T>
{
return undefined as any; // the implementation is not important
}
const x: Observable<boolean> = observable(false);
This code has one compilation problem:
Type 'Observable<false>' is not assignable to type 'Observable<boolean>'.
Types of parameters 'value' and 'value' are incompatible.
Type 'boolean' is not assignable to type 'false'.
Of course casting the false as boolean works, but I do consider this as hack, not a solution (obviously we need cast on every occurrence of true/false).
Any way to actually solve this?
Edit: based on comment it is obvious that some type checking was changed. More examples can be seen here. Playground Link.
Is there any info (with explanation) for this change?
Edit2: as suggested in comments, I filed a bug report at https://github.com/microsoft/TypeScript/issues/48150