Typescript: Type inference is wrong

Created on 30 Apr 2020  路  6Comments  路  Source: microsoft/TypeScript


TypeScript Version:
3.8.3


Search Terms:
type inference

Reproduction link:
https://codesandbox.io/s/dreamy-chandrasekhar-7pqfh

Steps to reproduce:
Check src/index.ts line 5.

Expected behavior:
Type of a.a is number.

Actual behavior:
Type of a.a is Ref<number>.

Related Issues:
https://github.com/vuejs/vue-next/issues/1083


See the comments in src/index.ts.

External

Most helpful comment

I doesn't look like an issue at all, you probably meant a.a.value++.

At runtime, a.a is 0 and a.a.value is undefined, and after executing a.a++ a.a is now 1, so no.

All 6 comments

This is not an typescript issue, this is an issue of vue UnwrapRef implementation.

~I doesn't look like an issue at all, you probably meant a.a.value++.~

I doesn't look like an issue at all, you probably meant a.a.value++.

At runtime, a.a is 0 and a.a.value is undefined, and after executing a.a++ a.a is now 1, so no.

The problem is that Vue 3 expects Node and Window to be defined; without it, it implicitly has an error. When we look up Node or Window, it's treated as any instead of some opaque type. Maybe @yyx990803 should see this.

If we had opaque placeholder types/forward declarations (https://github.com/microsoft/TypeScript/issues/31894) for Node and the like, I think this would be a non-issue, but this is likely to only be available in the next version. (@ahejlsberg)

A hack that Vue 3.0 can make in the meantime is add some global declarations that are certain not to conflict for Node and the rest:

interface Node {
  nodeName: string;
  nodeType: number;
  textContent: string;
}

Thanks @DanielRosenwasser - tracking in https://github.com/vuejs/vue-next/issues/1083, I think we can close this one.

Thanks everyone, as you said this is not an typescript issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

uber5001 picture uber5001  路  3Comments

wmaurer picture wmaurer  路  3Comments

DanielRosenwasser picture DanielRosenwasser  路  3Comments

bgrieder picture bgrieder  路  3Comments

Antony-Jones picture Antony-Jones  路  3Comments