How to write javascript code in typescript

var timer;

var compareDate = new Date();
compareDate.setDate(compareDate.getDate() + 9
); //just for this demo today + 7 days

timer = setInterval(function() {
timeBetweenDates(compareDate);
}, 1000);

function timeBetweenDates(toDate) {
var dateEntered = toDate;
var now = new Date();
var difference = dateEntered.getTime() - now.getTime();

if (difference <= 0) {
// Timer done
clearInterval(timer);
} else {
var seconds = Math.floor(difference / 1000);
var minutes = Math.floor(seconds / 60);
var hours = Math.floor(minutes / 60);
var days = Math.floor(hours / 24);

hours %= 24;
minutes %= 60;
seconds %= 60;

$("#days").text(days);
$("#hours").text(hours);
$("#minutes").text(minutes);
$("#seconds").text(seconds);

}
}

Really what you need to spend a little time on is learning ES6. For example let or const might be the better choice instead of var. Also, I see you use $(), which makes me think you might be leaning in jQuery for DOM access. That also will trip you up with Ionic development.

There are some great tutorials out there and you should be up and coding in ES6 & Typescript in no time