From f241f1ca98073a10a147d853bd7edf12a95f3635 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Wed, 23 Sep 2020 13:51:12 -0700 Subject: [PATCH] Fix Typescript 4.1 compile error Typescript 4.1 will have [stricter rules for type predicates](https://github.com/microsoft/TypeScript/pull/39258) like ```ts export const isObject = (val: unknown): val is Record => 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. --- packages/reactivity/src/collectionHandlers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/reactivity/src/collectionHandlers.ts b/packages/reactivity/src/collectionHandlers.ts index f7ae9ae5dc6..93d09770c9a 100644 --- a/packages/reactivity/src/collectionHandlers.ts +++ b/packages/reactivity/src/collectionHandlers.ts @@ -21,7 +21,7 @@ const toReactive = (value: T): T => isObject(value) ? reactive(value) : value const toReadonly = (value: T): T => - isObject(value) ? readonly(value) : value + isObject(value) ? readonly(value as Record) : value const toShallow = (value: T): T => value