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

defineComponent infers props incorrectly when prop is Function type #1891

Closed
jw-foss opened this issue Aug 19, 2020 · 4 comments · Fixed by #1896
Closed

defineComponent infers props incorrectly when prop is Function type #1891

jw-foss opened this issue Aug 19, 2020 · 4 comments · Fixed by #1896

Comments

@jw-foss
Copy link

jw-foss commented Aug 19, 2020

Version

3.0.0-rc.5

Reproduction link

https://codesandbox.io/s/cranky-gareth-k92ch?file=/src/test.ts

Screenshots

image
image

Steps to reproduce

Before get started, make sure you have set your script language to ts

  1. Define a new component with defineComponent method
  2. Define any prop with type Function as PropType<() => void>
  3. Assign default value to the prop you just defined as NOOP in @vue/shared or () => { }
  4. Define a setup method
  5. Try calling the method you just defined directly as props.methodYouDefined()
  6. Observe

What is expected?

Expect the type system correctly infers the type of the prop that you defined.
The current implementation says the prop.value's type is (void | () => void), which is combined result of prop.type and typeof result of prop.default.
the expected result should be () => void which is the combined result of prop.type and typeof prop.default

What is actually happening?

(property) propYouDefined: void | (() => void)

This expression is not callable.
  
Not all constituents of type 'void | (() => void)' are callable.
   
 Type 'void' has no call signatures.
@HcySunYang
Copy link
Member

This will be fixed in the next release.

@posva
Copy link
Member

posva commented Aug 19, 2020

@HcySunYang I also thought this was fixed by your PR but it seems to fail: master...test/types/props-default

@pikax
Copy link
Member

pikax commented Aug 19, 2020

Is not fixed yet.

This is caused by the DefaultFactory adding the return value type.

@HcySunYang
Copy link
Member

@pikax Aha, I just saw that you have submitted a PR for this issue, but our approach is different.

@github-actions github-actions bot locked and limited conversation to collaborators Nov 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
4 participants