Skip to content

Error on casting on MST: value "2022-04-18T16:53:06.000Z" is not assignable to type: Date #1898

Answered by BATCOH
Zeioth asked this question in Q&A
Discussion options

You must be logged in to vote

As it says in the error, types.Date accepts numbers and Date instances as a value.
But your value is a string. You can convert it to Date, something like that:

// ...
self.setPitchers(resp.data.data.pitchers.pitchers.map(pitcher => {
  ...pitcher,
  firstPitchedAt: new Date(pitcher.firstPitchedAt),
  lastPitchedAt: new Date(pitcher.lastPitchedAt),
}))
// ...

Alternatively, you can create your own custom type that would handle a string to a date conversion.

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by Zeioth
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants