core icon indicating copy to clipboard operation
core copied to clipboard

defineComponent (function syntax): exposed things loose typing and became any type

Open zfeher opened this issue 2 months ago • 1 comments

Vue version

3.5.22

Link to minimal reproduction

minimal repro

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

zfeher avatar Oct 05 '25 14:10 zfeher

I think it may be related to type inference and the difference in the "return" statements. From official documentation: Image Type Inference

xiaocainiao633 avatar Oct 14 '25 15:10 xiaocainiao633

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');
  },
});

wangcch avatar Dec 18 '25 11:12 wangcch