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

[Vue 3] Support nullable Function props #2898

Closed
4 tasks done
AverageHelper opened this issue Apr 28, 2021 · 3 comments
Closed
4 tasks done

[Vue 3] Support nullable Function props #2898

AverageHelper opened this issue Apr 28, 2021 · 3 comments
Labels

Comments

@AverageHelper
Copy link

  • I have searched through existing issues
  • I have read through docs
  • I have read FAQ
  • I have tried restarting VS Code or running Vetur: Restart VLS

Info

  • Platform: macOS
  • Vetur version: 0.33.1
  • VS Code version: 1.55.2

Problem

Conversion of type 'FunctionConstructor' to type 'PropType<OnSelectCallback | null>' may be a mistake because neither type sufficiently overlaps with the other.

Screen Shot 2021-04-28 at 8 35 58 AM

Reproducible Case

https://github.com/AverageHelper/prop-type-function-or-null

  • Set "strict": true in the tsconfig that manages the vue file in question.
  • Create a function callback signature type to use as a prop type
  • Add a prop whose type is Function and default is null
  • Augment the function type with a PropType that includes your custom callback signature and null
  • Observe error
@AverageHelper
Copy link
Author

AverageHelper commented Apr 30, 2021

This issue only occurs when the PropType annotation contains null. Vetur takes a normal function signature there just fine.

Since other prop types allow being augmented with null, and Vue has supported adding function signatures to props since #9733, I'm fairly certain this syntax should work.

Nullable function props are useful over events in the case where a component should behave differently based on the existence of a callback function. For example, a component may in some contexts be interactive, perhaps indicating in its UI that it is interactive, and calling a callback function passed by its parent component. In other contexts, the same component may only display data, but formatted in the same manner as the interactive version. I don't know a way to have a component check that its parent component handles an event, so function props have been a good way for us to make that check.

@yoyo930021
Copy link
Member

It's problem in vue 3 TypeScript type information.
Please report to vue-next project

@AverageHelper
Copy link
Author

Issue been reported at vue-next#3760.

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

No branches or pull requests

2 participants