Skip to content
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

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

Closed
pikax opened this issue May 10, 2022 · 1 comment · Fixed by #7338
Closed

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

pikax opened this issue May 10, 2022 · 1 comment · Fixed by #7338

Comments

@pikax
Copy link
Member

pikax commented May 10, 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


vuejs/language-tools#1275

@LinusBorg LinusBorg changed the title Type is lost when returning a same name property on the setup. Type is lost when returning a property from setup that uses the name of a prop. May 10, 2022
@LinusBorg
Copy link
Member

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants