core
core copied to clipboard
defineComponent (function syntax): exposed things loose typing and became any type
Vue version
3.5.22
Link to minimal reproduction
Steps to reproduce
1, open minimal repro and hoover over comp?.something} to see its inferred type (any)
2, open Comp.ts, find SomethingT and hoover over to see the inferred type (`any).
What is expected?
The type of comp.something should be 'something' literal type like in its definition.
What is actually happening?
The type of comp.something is any.
See compB.something (options syntax) which works correctly.
System Info
Any additional comments?
No response
I think it may be related to type inference and the difference in the "return" statements.
From official documentation:
Type Inference
Not related to function syntax.
// Exposed things also become "any"
export const CompB = defineComponent({
name: 'CompB',
setup(props, { expose }) {
const something = ref('something' as const);
expose({ something });
return () => h('div', 'CompB');
},
});