Skip to content

Ref unwrapping causes generic type inference to fail  #1930

@stefnotch

Description

@stefnotch

Version

3.0.0-rc.7

Reproduction link

https://codesandbox.io/s/stupefied-beaver-500yq?file=/src/test.ts:0-404

Steps to reproduce

Write the following, reasonably minimal code.

import { reactive, ComputedRef } from "vue";

interface Foo {
  position: number;
}

interface Bar {
  position: number;
  callback: (data: any) => void;
}

function createStuff(name: string, position: ComputedRef<number>) {
  const a: Foo = reactive({
    position: position,
  });

  const b: Bar = reactive({
    position: position, // Issue happens here
    callback: (v) => {},
  });
}

What is expected?

That the types are inferred correctly.

What is actually happening?

In the Bar case, Typescript complains about Type 'ComputedRef<number>' is not assignable to type 'number'. In the Foo case, everything works as expected.


This might as well be a bug with Typescript, but considering that it affects Vue's reactive API due to the automatic ref unwrapping, I thought I'd open it here first.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions