TypeScript: Type 'X' is not assignable to type 'X'.
Bug Report
Since 4.6 TS is complaining about that false
is not assignable to boolean
, when it is “wrapped by interface”.
🔎 Search Terms
4.6 type
🕗 Version & Regression Information
- This is a compile problem
- This changed between versions 4.5.5 and 4.6
⏯ Playground Link
💻 Code
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);
🙁 Actual behavior
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'.
🙂 Expected behavior
No compiler problem as in previous versions.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 26 (7 by maintainers)
For the record, the reason for the type error:
@maskmaster to be honest I am not sure. I only know that what worked previously does not work now. As @whzx5byb pointed out, the whole thing may be “reversed” - it was working because of less perfect previous TS version that allowed this and now it is not working because simply it should not work in the first place. I am not good at type theory at all, so anybody else have to say funded words. Anyway, I am reopening this in hope for clarification.