-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
TS: defineComponent doesn't return a Component #993
Comments
From what I've learned, I've done also an hack to make |
@pikax that's fine, I figured there had to be a reason why From a public API perspective, can I suggest that you do a bit of renaming type? Can |
Even with the rename it makes really hard to enforce the correct types validation, because when you have the interface The tests I was getting trouble with were the if we are too loose, this will not pass describe('h inference w/ Fragment', () => {
// only accepts array children
h(Fragment, ['hello'])
h(Fragment, { key: 123 }, ['hello'])
expectError(h(Fragment, 'foo'))
expectError(h(Fragment, { key: 123 }, 'bar'))
}) making the it too strict will make this fail // #922
describe('h support for generic component type', () => {
function foo(bar: Component) {
h(bar)
h(bar, 'hello')
h(bar, { id: 'ok' }, 'hello')
}
foo({})
}) Because we want |
Version
3.0.0-beta.2
Reproduction link
https://codesandbox.io/s/amazing-meitner-tgk24?file=/src/main.ts
Steps to reproduce
See
main.ts
in repro.I'm having typing issues with
defineComponent
once more, it seems to me the root cause is thatdefineComponent
TS definition pretends to return a ctor when it does not.This time the offender is
Component
: a union type that includes both stateful and functional components but not ctor, which would be ok ifdefineComponent
wasn't lying about its return type.Out of curiosity, I looked at how
createApp
manages to do it: its first argument is aPublicApiComponent
, which turns out to be... the union ofComponent
and Ctor!This is just confusing, not to mention
PublicApiComponent
is not exported, so there's no type in Vue API that can be used to describe a "component" type that would work in all cases.What is expected?
Code should compile? Or a good alternative be provided?
What is actually happening?
TS error as Ctor is not a Component.
The text was updated successfully, but these errors were encountered: