“One of Ionic's main goals is to make app development as quick and easy as possible, and the tooling
support TypeScript gives us with autocompletion, type checking and source documentation really aligns with that.”
— Tim Lancina, Tooling Developer - Ionic
A little of history
TypeScript is a superset of JavaScript, which is compiled directly in javascript, adds a static typing and class-based objects. is structured, object oriented, fully functional and generic, used to develop applications both on the server side and the client side, normally uses the extension .ts
Working on
Many IDEs support TypeScript without the need for additional configuration, but TypeScript can also be compiled using Node.JS from a command line.
I personally use Visual studio, since the 2015 version includes by default TypeScript.
Installing the command line interface
Install Node.js.
Install the npm package globally
To be able to install typescript in a way that commands can be used on any directory, we must install it globally as follows
npm install -g typescript
Compiling TypeScript code
Is used to compile typescript the command tsc
for example:
tsc my-code.ts
Basic syntax && The Hello World
as typescript is a superset of JavaScript, as code written in javascript is valid. typescript adds new features making it much more strongly-typed
Type declarations
you can add type declarations to the variables, function parameters and function return types, what did you mean by this? Let's see the following:
var num: number = 5;
the compiler will check the types (when possible) during the compilation and generate the corresponding errors, for example:
var num:number* = 5;
num = "this is a string cadene";
//this generate a error: Type 'string' is not assignable to type 'number'.
you can check more types here http://www.typescriptlang.org/docs/handbook/basic-types.html
Hello World
we in typescript can define classes like this:
`class HelloWorld {
greeting: string;
constructor(message: string) {
this.greeting = "Hello World by: "+message;
}
greet(): string {
return this.greeting;
}
};`
We can use this class as follows
'let greeter = new Greeter ("Chocolatoso");'
'console.log (HelloWorld.greet ());' -> which prints: Hello World by: Chocolatoso
Here we have a class, HelloWorld, which has a constructor and a greeting method.
You can build an instance of that class using
the keyword new
and we will pass string so that the greeting method comes out in the console.
You got a 3.67% upvote from @postpromoter courtesy of @chocolatoso!
Want to promote your posts too? Check out the Steem Bot Tracker website for more info. If you would like to support the development of @postpromoter and the bot tracker please vote for @yabapmatt for witness!
You got a 3.88% upvote from @upme thanks to @chocolatoso! Send at least 3 SBD or 3 STEEM to get upvote for next round. Delegate STEEM POWER and start earning 100% daily payouts ( no commission ).
This is an advertised post
The author of this post or one of his supporters has used one or more paid services to promote this post. This post's valuation and number of upvotes does not represent human curation. This means this post's valuation does not represent community appreciation and should be viewed as advertised content.
If you are new to these services please be warned that bid voting is a huge gamble with little return on investment if not utilized right and might also lead to a net loss.
If you like this service please update this comment for visibility and to support paying for the server costs.