jacobcan118
jacobcan118

Reputation: 9099

typescript using the same variable after declare

how can I do following code in typescript like python?

let startDay: Date = new Date();
let startDay: string = `${startDay.toLocaleDateString('en-US')}`

? or I have to declare two different variable for type convention?

Upvotes: 0

Views: 108

Answers (1)

sgmonda
sgmonda

Reputation: 2729

Yo cannot declare the same variable twice in the same context. Javascript or Typescript will not let you do it. Furthermore, Typescript does not allow type mutation so if you use a Date type first, it cannot be changed.

If you don’t need to use the Date version just omit its declaration:

let startDay: string = new Date().toLocaleDateString('en-US');

Upvotes: 2

Related Questions