Skip to content

vue-component-meta: No way to identify array v.s. tuple #5402

Open
@thomasaull

Description

@thomasaull

Vue - Official extension or vue-tsc version

VSCode version

Vue version

3.5.16

TypeScript version

5.8.3

System Info

package.json dependencies

Steps to reproduce

Run vue-component-meta with the following component:

<template>
  <slot />
</template>

<script setup lang="ts">
type TupleAlias = [string]

export interface Props {
  tuple: [string]
  stringArray: string[]
  tupleAlias: TupleAlias
}

const props = withDefaults(defineProps<Props>(), {})
</script>

What is expected?

The exported type information should allow to identify a tuple

What is actually happening?

The output is as follows (stripped unnecessary parts):

{
  "type": 1,
  "props": [
    {
      "name": "tuple",
      "global": false,
      "description": "",
      "tags": [],
      "required": true,
      "type": "[string]",
      "declarations": [
        {
          "file": "[...]/FixedArray.vue",
          "range": [115, 136]
        }
      ],
      "schema": { "kind": "array", "type": "[string]", "schema": ["string"] }
    },
    {
      "name": "stringArray",
      "global": false,
      "description": "",
      "tags": [],
      "required": true,
      "type": "string[]",
      "declarations": [
        {
          "file": "[...]/FixedArray.vue",
          "range": [139, 154]
        }
      ],
      "schema": { "kind": "array", "type": "string[]", "schema": ["string"] }
    },
    {
      "name": "tupleAlias",
      "global": false,
      "description": "",
      "tags": [],
      "required": true,
      "type": "TupleAlias",
      "declarations": [
        {
          "file": "[...]/FixedArray.vue",
          "range": [157, 179]
        }
      ],
      "schema": { "kind": "array", "type": "TupleAlias", "schema": ["string"] }
    }
  ]
}

As you can see the schema for all three props is ["string"] regardless if it’s a string[] or [string] type. In my project I have the requirement to make a clear distinction between tuples and regular arrays, which is currently not possible as it seems. I could check if the type starts with [ but this breaks with the tupleAlias example

Link to minimal reproduction

No response

Any additional comments?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions