Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Typescript 4.1 compile error #2219

Merged
merged 1 commit into from Sep 28, 2020

Conversation

sandersn
Copy link
Contributor

Typescript 4.1 will have stricter rules for type predicates like

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.

Discovered in the Typescript user tests: https://github.com/microsoft/TypeScript/pull/40156/files#diff-3ff86ade791953efc13be67665963d94

Fixes #2218

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.
@yyx990803 yyx990803 merged commit d52d139 into vuejs:master Sep 28, 2020
@yyx990803
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

vue-next doesn't build on Typescript 4.1
2 participants