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

函数模板引用类型完善 #10897

Closed
gumingWu opened this issue May 9, 2024 · 1 comment
Closed

函数模板引用类型完善 #10897

gumingWu opened this issue May 9, 2024 · 1 comment

Comments

@gumingWu
Copy link

gumingWu commented May 9, 2024

Vue version

latest

Link to minimal reproduction

https://play.vuejs.org/#eNqFU9uO0zAQ/RXjl6TSkoDgqaQVF1UChAAtSDys9yEkk9S7jm35EipF+XfGdtPuSnt5imfOOeMz48lEP2hdjB7omla2MVw7YsF5TUQt+w2jzjK6ZZIPWhlHJmKgIzPpjBpIhrLsBH1Sgz7mizIEoWr2jkkmGyWtI4PtySbo8+wzCKHIH2VE+yJbnSkIfuP4TbSr6xXKE1K37SXevCE5iBXZbMnEJFn4xVgLD4X2dh9gFM2LrhG8uQ2yR0RXr66LfXCTH2VVmaaAPWPgYNCidoARIdX+9XaaYh/zXJUYxSyX2jsyvhxUCwInhjijpExgnMoar0RgsZ56CdGZ99c7pyR5H/0iN35x8tFbVSYYqVV5xxK9wOfBPjveFzdWSXzD2CHK8VouwPzQjuMcGF2n3gNWY8V/X2POGQ8XS77ZQ3P7QP7GHkKO0Z8GLJgRGD1hrjY9uATvfn2HA55PIA7EC2Q/AV6CVcIHj4n20csWbd/hRbdf4opx2f+2u4MDaZemgtHAnCOfUVy5MPHHWj/bfVO8jTp8c5zisq7P/ASdl00oSo4bkwqHRVMCCqH6PItIWGmszGQLHZewO2hlIY/kiKPZGSlPrVrLx3jAoxXKLWtSpvz9LZj/AwMZQfs=

Steps to reproduce

repo 由于没有类型提示,所以在这里详细说明我目前遇到的问题

image

目前有个场景,需要使用 addRef 方法把 el 添加到 refList 数组中,由于使用了 lang=ts 所以需要补全 addRef 的入参类型

image

按照 VNodeRef 类型,函数形式的模板引用入参类型为 Element | ComponentPublicInstance | null 于是我按照这样进行配置

image

这时候确实没 ts 报错提示了

image

image

可是这时候就没了 RefTest 组件的方法提示了

What is expected?

期望在函数模板引用中,el 的类型可以是当前组件的类型,而不是通用的 ComponentPublicInstance

What is actually happening?

如上

System Info

No response

Any additional comments?

No response

@yyx990803
Copy link
Member

一个函数声明可以被用在任何地方,不能从某一个被使用的地方倒推出其参数类型。这是受 TypeScript 本身类型推导所限,不是 Vue 能解决的。

@github-actions github-actions bot locked and limited conversation to collaborators May 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants