Subscribe on changes!

Setting "Date" type as props will infer to string in the setup function

avatar
Nov 25th 2020

Version

3.0.2

Reproduction link

https://codesandbox.io/s/laughing-galois-gh0q4

Steps to reproduce

define props

{
  props: {
    date: Date
  },
  setup(props) {
    // string type
    props.date 
  }

What is expected?

props.date should be Date type

What is actually happening?

props.date is string type

avatar
Nov 25th 2020

As a workaround you can do date: Date as PropType<Date>,

avatar
Dec 23rd 2020

Hi @Zcating , that's strange, I get the right result in your Reproduction link: image

And even I create a project with vue-cli, the type of date is still Date.

Environment Info:

  System:
    OS: Windows 10 10.0.19041
    CPU: (12) x64 Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz
  Binaries:
    Node: 12.4.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.4 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.9.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 87.0.4280.88
avatar
Dec 23rd 2020

@Alanscut This is a typing issue, you need to add code inside setup to show the TS error

avatar
Dec 23rd 2020

@Alanscut This is a typing issue, you need to add code inside setup to show the TS error

Thanks!

avatar
Dec 28th 2020

I had the same problem and the workaround worked for me but i'm still interested on why that happen. Just saw related issue #2676