Subscribe on changes!

Type is lost when returning a property from setup that uses the name of a prop.

avatar
May 10th 2022

Version

3.2.33

Reproduction link

www.typescriptlang.org/play

Steps to reproduce

test.ts
import { defineComponent, PropType } from "vue";

export enum ValidSize {
  sm = "sm",
}
export type ValidSizeType = keyof typeof ValidSize;
export function sizeProp<T extends ValidSize>(defaultSize?: T) {
  return {
    size: {
      type: String as PropType<ValidSizeType>,
      default: defaultSize, 
      validator: (value: ValidSize) => {
        if (value === null) return true;
        return !!ValidSize[value];
      },
    },
  };
}
const Comp = defineComponent({
  props: {
    ...sizeProp(ValidSize.sm),
  },

  setup() {
    return {
      size: 1, // if you comment this, it works
    };
  },
});

type CompType = InstanceType<typeof Comp>; // never

What is expected?

Comp to not be never

What is actually happening?

Comp should keep the correct type


https://github.com/johnsoncodehk/volar/issues/1275

avatar
May 10th 2022

Took the freedom of changing the title to better reflect the issue.