Compiling a Typescript file using the command-line
Please read the post about downloading the latest Typescript here.
Once you have downloaded Typescript file, you can compile it using the command tsc from the C:\ prompt.
Here is a Typescript file, Person.ts:
--------------------------------
interface Person {
age: number,
name: string,
say(): string
}
let mike = {
age: 25,
name:"Mike",
say: function() {
return "My name is " + this.name +
" and I'm " + this.age + " years old!"
}
}
function sayIt(person: Person) {
return person.say();
}
--------------------
Save it to a location of your choice as shown.
Typescriptsample_0
Now compile it using the command tsc as shown here:
----------
C:\Users\Owner> tsc Person.ts
C:\Users\Owner>dir
------------
The program compiles it to a JavaScript file as shown:
-----------
Typescriptsample_1.png
The JavaScript file now reads as shown:
-------------
var mike = {
age: 25,
name: "Mike",
say: function () {
return "My name is " + this.name +
" and I'm " + this.age + " years old!";
}
};
function sayIt(person) {
return person.say();
}
console.log(sayIt(mike));
--------------------------------
Notice the strong typing in the Typescript file.
Once you have downloaded Typescript file, you can compile it using the command tsc from the C:\ prompt.
Here is a Typescript file, Person.ts:
--------------------------------
interface Person {
age: number,
name: string,
say(): string
}
let mike = {
age: 25,
name:"Mike",
say: function() {
return "My name is " + this.name +
" and I'm " + this.age + " years old!"
}
}
function sayIt(person: Person) {
return person.say();
}
--------------------
Save it to a location of your choice as shown.
Typescriptsample_0
Now compile it using the command tsc as shown here:
----------
C:\Users\Owner> tsc Person.ts
C:\Users\Owner>dir
------------
The program compiles it to a JavaScript file as shown:
-----------
Typescriptsample_1.png
The JavaScript file now reads as shown:
-------------
var mike = {
age: 25,
name: "Mike",
say: function () {
return "My name is " + this.name +
" and I'm " + this.age + " years old!";
}
};
function sayIt(person) {
return person.say();
}
console.log(sayIt(mike));
--------------------------------
Notice the strong typing in the Typescript file.
Comments