Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Type error with generics and ref #5491

@tkalmar

Description

@tkalmar

Vue - Official extension or vue-tsc version

3.0.1

VSCode version

1.101.2

Vue version

3.4.32

TypeScript version

5.8.3

System Info

System:
    OS: Linux 5.15 Ubuntu 22.04.5 LTS 22.04.5 LTS (Jammy Jellyfish)
    CPU: (16) x64 11th Gen Intel(R) Core(TM) i7-11850H @ 2.50GHz
    Memory: 111.16 GB / 125.50 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 20.16.0 - ~/.nvm/versions/node/v20.16.0/bin/node
    npm: 10.8.1 - ~/.nvm/versions/node/v20.16.0/bin/npm
  Browsers:
    Chromium: 138.0.7204.49

package.json dependencies

Steps to reproduce

Having a minimal generic component:

<script setup lang="ts" generic="T extends string | number">
  import { ref } from 'vue';

  const x = ref<Set<T>>(new Set());
</script>

The type of x is infered to: Ref<Set<UnwrapRefSimple<T>> & Omit<Set<T>, keyof Set<any>>>
The UnwrapRef is unexpected and leads to typ errors when using the value

What is expected?

When omiting the type information i get Ref<Set<unknown> & Omit<Set<unknown>, keyof Set<any>>>
So the expected type for x should be Ref<Set<T> & Omit<Set<T>, keyof Set<any>>>

What is actually happening?

The wrong type is inferred

Link to minimal reproduction

No response

Any additional comments?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already exists

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions