Skip to content

Commit f241f1c

Browse files
committed
Fix Typescript 4.1 compile error
Typescript 4.1 will have [stricter rules for type predicates](microsoft/TypeScript#39258) like ```ts export const isObject = (val: unknown): val is Record<any, any> => val !== null && typeof val === 'object' ``` As a result of these rules, an expression in collectionHandlers.ts in the reactivity package doesn't get narrowed to the type it did in TS 4.0 and below. Instead it gets an intersection type, which doesn't work with subsequent code. I restored the old type using a cast, since that's essentially what the old version of Typescript was doing here.
1 parent 64f44c6 commit f241f1c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

packages/reactivity/src/collectionHandlers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const toReactive = <T extends unknown>(value: T): T =>
2121
isObject(value) ? reactive(value) : value
2222

2323
const toReadonly = <T extends unknown>(value: T): T =>
24-
isObject(value) ? readonly(value) : value
24+
isObject(value) ? readonly(value as Record<any, any>) : value
2525

2626
const toShallow = <T extends unknown>(value: T): T => value
2727

0 commit comments

Comments
 (0)