Typescript Date Type?

VSO picture VSO · Aug 3, 2017 · Viewed 327k times · Source

How do I express dates in TypeScript? Dates aren't a TypeScript type, so do I use 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.

Answer

str picture str · Aug 3, 2017

The answer is super simple, the type is Date:

const d: Date = new Date(); // but the type can also be inferred from "new Date()" already

It is the same as with every other object instance :)