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
This may be intended, but I want a bug to track this in case others run into it.
// @strict: trueexportinterfaceRef<T=any>{value: T}typeUnwrapRef<T>=TextendsRef<infer V> ? V : neverdeclarefunctionreadonly<T>(target: T): UnwrapRef<T>consttoReadonly=<Textendsunknown>(value: T): T=>// readonly(value as T & Record<any,any>)isObject(value) ? readonly(value) : valuedeclarefunctionisObject(val: unknown): val is Record<any,any>
This is an error without --strict on 4.0, but not with --strict. In 4.1, it's an error for both.
Expected behavior:
No error and value: Record<any, any> in readonly(value).
Actual behavior:
Error and value: T & Record<any, any> in readonly(value):
Type 'T | UnwrapRef<T & Record<any, any>>' is not assignable to type 'T'.
'T | UnwrapRef<T & Record<any, any>>' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'unknown'.
Type 'UnwrapRef<T & Record<any, any>>' is not assignable to type 'T'.
'UnwrapRef<T & Record<any, any>>' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'unknown'.
Type 'unknown' is not assignable to type 'T'.
'unknown' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'unknown'.
Also I'm not sure where the last two lines of the error come from. They don't seem to follow from the previous lines.
Workaround
readonly(value as Record<any, any>) to restore the old type of value: casting to subtype is allowed.
The text was updated successfully, but these errors were encountered:
👋 Hi, I'm the Repro bot. I can help narrow down and track compiler bugs across releases! This comment reflects the current state of the repro in this issue running against the nightly TypeScript. If something changes, I will post a new comment.
Type 'T | UnwrapRef<T & Record<any, any>>' is not assignable to type 'T'.
'T | UnwrapRef<T & Record<any, any>>' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'unknown'.
Type 'UnwrapRef<T & Record<any, any>>' is not assignable to type 'T'.
'UnwrapRef<T & Record<any, any>>' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'unknown'.
Type 'unknown' is not assignable to type 'T'.
'unknown' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'unknown'.
Type 'T | UnwrapRef<T & Record<any, any>>' is not assignable to type 'T'.
'T | UnwrapRef<T & Record<any, any>>' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'unknown'.
Type 'UnwrapRef<T & Record<any, any>>' is not assignable to type 'T'.
'UnwrapRef<T & Record<any, any>>' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'unknown'.
Type 'unknown' is not assignable to type 'T'.
'unknown' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'unknown'.
So, we think this is a real compiler error that used to be masked - 4.0 and and below would effectively give an any for the T side of the compiler error previously
const toReadonly = <T extends unknown>(value: T): T =>
// readonly(value as T & Record<any,any>)
isObject(value) ? readonly(value) : value
Effectively gives either { value: 123} or 123 which aren't assignable - thus the error is legit 👍🏻
Uh oh!
There was an error while loading. Please reload this page.
This may be intended, but I want a bug to track this in case others run into it.
This is an error without
--strict
on 4.0, but not with--strict
. In 4.1, it's an error for both.Expected behavior:
No error and
value: Record<any, any>
inreadonly(value)
.Actual behavior:
Error and
value: T & Record<any, any>
inreadonly(value)
:Also I'm not sure where the last two lines of the error come from. They don't seem to follow from the previous lines.
Workaround
readonly(value as Record<any, any>)
to restore the old type ofvalue
: casting to subtype is allowed.The text was updated successfully, but these errors were encountered: