snippettypescriptCritical
How do I express a date type in TypeScript?
Viewed 0 times
typescripthowdateexpresstype
Problem
How do I express dates in TypeScript? Dates aren't a TypeScript type, so do I use
I couldn't find much on Google, despite it being such a simple question.
any or object? Seems like there would be a "right" way to do:let myDate: any = new Date();I couldn't find much on Google, despite it being such a simple question.
Solution
The type is
It is the same as with every other object instance :)
Date:const d: Date = new Date(); // but the type can also be inferred from "new Date()" alreadyIt is the same as with every other object instance :)
Code Snippets
const d: Date = new Date(); // but the type can also be inferred from "new Date()" alreadyContext
Stack Overflow Q#45485073, score: 607
Revisions (0)
No revisions yet.