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

fix(language-core): prevent the generation of generics in JS #4836

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

KazariEX
Copy link
Collaborator

fix #4826

Copy link

pkg-pr-new bot commented Sep 10, 2024

Open in Stackblitz

vue-component-meta

pnpm add https://pkg.pr.new/vuejs/language-tools/vue-component-meta@4836

vue-component-type-helpers

pnpm add https://pkg.pr.new/vuejs/language-tools/vue-component-type-helpers@4836

@vue/language-core

pnpm add https://pkg.pr.new/vuejs/language-tools/@vue/language-core@4836

@vue/language-plugin-pug

pnpm add https://pkg.pr.new/vuejs/language-tools/@vue/language-plugin-pug@4836

@vue/language-server

pnpm add https://pkg.pr.new/vuejs/language-tools/@vue/language-server@4836

vue-tsc

pnpm add https://pkg.pr.new/vuejs/language-tools/vue-tsc@4836

@vue/language-service

pnpm add https://pkg.pr.new/vuejs/language-tools/@vue/language-service@4836

@vue/typescript-plugin

pnpm add https://pkg.pr.new/vuejs/language-tools/@vue/typescript-plugin@4836

commit: cd14b23

@zhiyuanzmj
Copy link
Collaborator

How about add a unit test

@KazariEX
Copy link
Collaborator Author

Type assertion expressions can only be used in TypeScript files.

I don't know how to check the type of it :)

@zhiyuanzmj
Copy link
Collaborator

Added

zhiyuanzmj
zhiyuanzmj previously approved these changes Sep 10, 2024
@phil294
Copy link

phil294 commented Sep 13, 2024

With this PR, the inferred type of a useTemplateRef var is Readonly<ShallowRef<unknown>>, i.e. the html element type isn't determined based on the string key provided unless you're using TS. Is this the intended behavior?

Both problems specified in the issue itself however are indeed fixed with this, thanks for your work :)

@KazariEX
Copy link
Collaborator Author

This PR only prevents injecting generics in JS to avoid unexpected type inference. When you don't use generics, useTemplateRef returns Readonly<ShallowRef<unknown>> by default.

When using TypeScript, Vue's IDE support and vue-tsc will automatically infer the type of inputRef.value based on what element or component the matching ref attribute is used on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

useTemplateRefs falsely returns boolean
3 participants