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

setup types Date prop as string #3164

Closed
canac opened this issue Feb 4, 2021 · 2 comments
Closed

setup types Date prop as string #3164

canac opened this issue Feb 4, 2021 · 2 comments

Comments

@canac
Copy link

canac commented Feb 4, 2021

Version

3.0.5

Reproduction link

https://codesandbox.io/s/setup-props-date-3jkl9?file=/src/main.ts

Steps to reproduce

Create a component using the composition API that has a prop with the Date type.

import { computed, defineComponent, toRefs } from "vue";

defineComponent({
  props: {
    date: {
      type: Date,
      required: true
    }
  },

  // The error is here: Vue thinks the type of props should be { date: string }
  setup(props: { date: Date }) {
    const { date } = toRefs(props);
    const formattedDate = computed((): string => date.value.toISOString());

    return {
      formattedDate
    };
  }
});

What is expected?

The property in the props dictionary that is an argument to the setup function has the type string.

What is actually happening?

The property in the props dictionary that is an argument to the setup function should have the type Date.

@canac
Copy link
Author

canac commented Feb 4, 2021

I discovered that defining setting the date type to Date as PropType<Date> and removing the type annotation from setup works, as suggested in #1494. That gets my code working again, but it seems a little hacky, and it would be nice if Vue could correctly infer prop types for dates like it can for numbers and strings.

@HcySunYang
Copy link
Member

Duplicate of #2668

@HcySunYang HcySunYang marked this as a duplicate of #2668 Feb 4, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Oct 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants