Skip to content

Commit

Permalink
Fix Typescript 4.1 compile error
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sandersn committed Sep 23, 2020
1 parent 64f44c6 commit f241f1c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/reactivity/src/collectionHandlers.ts
Expand Up @@ -21,7 +21,7 @@ const toReactive = <T extends unknown>(value: T): T =>
isObject(value) ? reactive(value) : value

const toReadonly = <T extends unknown>(value: T): T =>
isObject(value) ? readonly(value) : value
isObject(value) ? readonly(value as Record<any, any>) : value

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

Expand Down

0 comments on commit f241f1c

Please sign in to comment.