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

Type inference is wrong #38261

Closed
yangmingshan opened this issue Apr 30, 2020 · 6 comments
Closed

Type inference is wrong #38261

yangmingshan opened this issue Apr 30, 2020 · 6 comments
Labels
External Relates to another program, environment, or user action which we cannot control.

Comments

@yangmingshan
Copy link

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:
vuejs/core#1083


See the comments in src/index.ts.

@pikax
Copy link

pikax commented Apr 30, 2020

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

@ilogico
Copy link

ilogico commented Apr 30, 2020

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

@nmain
Copy link

nmain commented Apr 30, 2020

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.

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Apr 30, 2020

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 (#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;
}

@DanielRosenwasser DanielRosenwasser added the External Relates to another program, environment, or user action which we cannot control. label Apr 30, 2020
@yyx990803
Copy link

Thanks @DanielRosenwasser - tracking in vuejs/core#1083, I think we can close this one.

@yangmingshan
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
External Relates to another program, environment, or user action which we cannot control.
Projects
None yet
Development

No branches or pull requests

6 participants