Why not JavaScript?
$ whoami
Erik Wallin
Full stack developer
Consultant at DevCode
@c01ac0ca
interface Person {
firstName: string;
surName?: string;
}
class Demo {
company: string;
constructor(company, private presenter: Person) {
this.company = company;
}
greet() {
alert(this.presenter.firstName + ' says hello to ' + this.company);
}
}
let erik = <Person>{firstName: 'Erik'};
let demo = new Demo('Init', erik);
demo.greet();
[0] == 0; //true
[1] == [1]; //false
[1] == "1"; //true
...
// Quiz time!!!
init: function () {
this.constructor.__super__.init.apply(this, arguments);
}
...
...
// Creates an array of the array-like 'arguments'
var args = 1 <= arguments.length ? [].slice.call(arguments, 0) : [];
// This is a more correct way, still strange.
var args = Array.prototype.slice.call(arguments);
...
‘use strict’;
myVar = 4711; // error
Detect errors and potential problems in JavaScript code.
Dangerous constructions (e.g. prohibit ==)
Styling/coding conventions (spaces, indentation, etc)
Should be in a build step
// Declaration
let s: string;
//s = 1; // <-- compile error
// Function declaration
let fn = function(a: number): string {
return "" + a;
}
// type inference
let name = "kalle";
// Own types
interface Person {
firstName: string;
surName?: string;
age: number;
}
// Returns either number or string
let getSomething = function(person: Person): number | string {
if (person) {
return person.age;
} else {
return person.firstName;
}
}
enum Color {Red, Green, Blue};
let color: Color = Color.Green;
let myAny: any = "someString";
myAny = 1;
function warnUser(): void {
alert("This is my warning message");
}
interface Person {
firstName: string;
surName?: string;
}
let erik = <Person>{firstName: 'Erik'};
import {Component} from '@angular/core';
@Component({
selector: 'my-app',
template: '<h1>My First Angular 2 App</h1>'
})
export class AppComponent { }
$ cat tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true
}
}
Our full stack developers like TypeScript
Questions?