You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Brokenfunctionobservable<T>(value: T): Observable<T>{returnundefinedasany;// the implementation is not important}// Fixedfunctionobservable<T>(value: Textends infer U ? U: never): Observable<T>{returnundefinedasany;// the implementation is not important}
// Fixedfunctionobservable<T,U=any>(value?: Textends infer R ? R : U): unknownextendsT ? Observable<U> : Observable<T>{returnundefinedasany;// the implementation is not important}
The playground contains many examples and seems OK, of course anybody can check and correct if needed, I am no expert in this.
Hi, I believe I'm hitting the same issue when upgrading to typescript 4.6 but I might need some help understanding the workaround. Here is a minimum repro.
The ExtendedType is clearly assignable to the BaseType, but typescript wouldn't allow. Also, the error suggests that typescript is trying to assign BaseType to ExtendedType, which is opposite to the desired direction.
Should I manually patch the type definitely of KnockoutObservable? I'm not sure how that might work. Thank you and let me know if I should cross post to other repos.
Activity
maskmaster commentedon Mar 8, 2022
I added an answer in the stackoverflow question. We need to make sure that these two lines remain valid after any fix.
tomhanax commentedon Mar 8, 2022
For now the best I can offer is:
The playground contains many examples and seems OK, of course anybody can check and correct if needed, I am no expert in this.
Playground Link
brianmhunt commentedon Mar 8, 2022
Thanks @maskmaster , @tomhanax the answer & playground are very helpful.
direct link to the SO question
chuanqisun commentedon May 20, 2022
Hi, I believe I'm hitting the same issue when upgrading to typescript 4.6 but I might need some help understanding the workaround. Here is a minimum repro.
The
ExtendedTypeis clearly assignable to theBaseType, but typescript wouldn't allow. Also, the error suggests that typescript is trying to assignBaseTypetoExtendedType, which is opposite to the desired direction.Should I manually patch the type definitely of
KnockoutObservable? I'm not sure how that might work. Thank you and let me know if I should cross post to other repos.mbest commentedon Jul 15, 2022
This was fixed in TypeScript: microsoft/TypeScript#48380
phillipc commentedon Nov 22, 2025
We have corrected all the TKO typings in #202. Specifically, this case with a newer version of TypeScript.