Skip to content

Use better types to model prop type #7713

@zsky

Description

@zsky

Version

2.5.13

Reproduction link

https://github.com/zsky/vue-date-type-issue

Steps to reproduce

npm i
npm run build

What is expected?

No typescript error

What is actually happening?

Typescript report error: Property 'getTime' does not exist on type 'string'


I use vue with typescript, I want to set a component prop type as Date, so I do this:

Vue.extend({
  props: { start: Date },
  created() { 
     this.start;  // Expect type Date, but String
  }
});

Then I find something could be userful:
In options.d.ts,

export type Prop<T> = { (): T } | { new (...args: any[]): T & object }

Make a simple test:

function test<T>(opts: { p1: Prop<T> }): T {
    return {} as T;
}
let result = test({ p1: Date });  // Expect type Date, but String

But I still don't know how to solve it, thanks for any suggestion.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions