Skip to content

HTMLElement type is automatically expanded #416

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

Closed
ollieSk8 opened this issue Aug 25, 2021 · 6 comments
Closed

HTMLElement type is automatically expanded #416

ollieSk8 opened this issue Aug 25, 2021 · 6 comments
Labels
question Further information is requested

Comments

@ollieSk8
Copy link

ollieSk8 commented Aug 25, 2021

1 . define a custom hook useClickOutside and recive a argument elementRef ,the elementRef type is Ref<null | HTMLElement>
2. define a dropdownRef type is null or HTMLElement
3. template has a div set ref attribute dropdownRef

Result :
Here I think there may be a problem with the implementation of volar. It will directly expand the HTMLElement type, causing a mismatch of types.

//template  <div class="dropdown" ref="dropdownRef">

// custom hook

const useClickOutside = (elementRef: Ref<null | HTMLElement>): Ref<boolean> => {
    //some other code
}
 const dropdownRef = ref<null | HTMLElement>(null)
 const isClickOutside = useClickOutside(dropdownRef) //  causing a mismatch of types.

截屏2021-08-25 下午2 23 10

@johnsoncodehk
Copy link
Member

This may just a vue type problem. Please try move the code to *.ts to check if there is the same error.

@ollieSk8
Copy link
Author

This may just a vue type problem. Please try move the code to *.ts to check if there is the same error.

sorry, I don’t understand too much, what's that mean "Please try move the code to *.ts"?

@johnsoncodehk
Copy link
Member

Create foo.ts under same directory with Dropdown.vue, copy the Dropdown.ts script block code to foo.ts, and then check the error whether reproduce in foo.ts. (Similar to #415 (comment))

@ollieSk8
Copy link
Author

Create foo.ts under same directory with Dropdown.vue, copy the Dropdown.ts script block code to foo.ts, and then check the error whether reproduce in foo.ts. (Similar to #415 (comment))

截屏2021-08-25 下午2 47 06
The same error occurred

@johnsoncodehk
Copy link
Member

That confirmed this is pure TS problem not volar problem, please ask in Vue Land TS discord server.

@johnsoncodehk johnsoncodehk added the question Further information is requested label Aug 25, 2021
@ollieSk8
Copy link
Author

That confirmed this is pure TS problem not volar problem, please ask in Vue Land TS discord server.

ok ,thanks

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

No branches or pull requests

2 participants