Skip to content

Support component instance types #527

Open
@XioDone

Description

@XioDone

Clear and concise description of the problem

The method exposed by the component, refer to the component in the template, you need to manually import the component in the script, add a type.

const myFormRef = ref<InstanceType<typeof MyForm>>()

<template>
  <MyForm ref="myFormRef"/>
</template>

Suggested solution

Add a switch to option, automatically declare the instance type of a component in components.d.ts
image

// components.d.ts
export interface GlobalComponents {
  MyForm: typeof import('./components/MyForm.vue')['default']
  MyFormInstance: InstanceType<GlobalComponents['MyForm']>
}

Maybe there's a more elegant way.

Alternative

No response

Additional context

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions