-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
types(resolveType): fix defineComponent type error #10273
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
base: main
Are you sure you want to change the base?
types(resolveType): fix defineComponent type error #10273
Conversation
Size ReportBundles
Usages
|
Thank you for your contribution, do you mind explaining what's the intent of this? It seems you're not following the function declaration described in the docs. Vue relies on runtime to run validations, etc. Just defining the types is not enough, not sure what Look at this example import { defineComponent, h } from "vue";
export const Test = defineComponent((props) => {
return () => h('div', props.test || '[unknown]')
}, {})
h(Test, {
test: 'test'
}) // it will output `[unknown]` Without declaring the runtime Also introducing a new type I'll be closing this down, if you think I'm wrong, please let me know we can discuss and possibly reopen if needed. |
That seems to be a feature of JSX plugin, not vue/core @sxzz can you provide some insight?
That is just purely typescript test, you can test the runtime does not work! playground import { defineComponent, h, ref } from "vue";
export default defineComponent(
// TODO: babel plugin to auto infer runtime props options from type
// similar to defineProps<{...}>()
<T extends string | number>(props: { msg: T; list: T[] }) => {
// use Composition API here like in <script setup>
const count = ref(0)
return () => h('div', [props.msg, count.value].join(' '))
},
) The typescript on vue/core is intended to support all the runtime features, if it doesn't work at runtime, it should not be supported by vue/core types. |
Context: #7963 Evan wants to have a resolve type plugin (just like The JSX plugin works well but didn't for TypeScript. This PR is aimed at fixing type errors. |
When jsx-plugin.resolveType is true, adding
emit
orslot
todefineComponent
will in type error.[#8608 ]fix #8608