Software Architect / Developer
Develops webapps since 1999
Powering Mobility Business for a Smart World
26 countries, 160 products, 450 employees
More than 1M vehicles sold per year
Datacenter 1500 hosts, 60 TB RAM, 1500 TB disk
»How I Learned to Stop Worrying & Trust the Compiler«
class Person {
constructor(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
}
let person = new Person(1, 2);
person.mama = 'Mia';
person = Math.sqrt(person);
export class Person {
private dateOfBirth?: Date;
constructor(private firstName: string, private lastName: string) {
}
toString() {
return `${this.firstName} ${this.lastName} (${this.dateOfBirth})`;
}
}
let a: number;
function toLowerCase(a: string|null) {
return a ? a.toLowerCase() : null;
}
type AorB = 'A'|'B';
const x: AorB = 'A';
type BiFunc = (a: number, b: number) => number;
interface Person {
firstName: string;
lastName: string;
dateOfBirth?: Date;
}
class Employee implements Person {
constructor(public firstName: string, public lastName: string) {
}
}
const p = {
firstName: 'Chris',
lastName: 'Kö'
};
const person: Person = p;
person.dateOfBirth = new Date();
const name = 'Christian'; // no type needed
// even no types for complex stuff
document
.getElementById('id')
.addEventListener('click',
ev => alert(`${ev.clientX}, ${ev.clientY}`));
class Stack<T> {
private items: T[] = [];
public push(item: T) {
this.items.push(item);
}
public pop(): T {
return this.items.pop();
}
}
const stack = new Stack<string>();
stack.push("a");
const a = stack.pop(); // a is a string
d.ts
export
and import
@Component({a = '1'}) // <<-- decorator
class MyClass {
@measure // <<-- decorator
public doSomething() {
// ...
}
}
function measure(target: any, propertyKey: string,
descriptor: PropertyDescriptor) {
const originalFunction = descriptor.value;
descriptor.value = function (...args: any[]) {
const start = Date.now();
originalFunction.apply(target, args);
console.log(`${propertyKey} with params "${args}"
took ${Date.now() - start}ms`);
}
}
function loadUserName(userId) {
const url = `https://user-api/user/${userId}`;
return fetch(url)
.then(response => response.json())
.then(user => user.name);
}
async function loadUserName2(userId: string) {
const url = `https://user-api/user/${userId}`;
const response = await fetch(url);
const user = await response.json();
return user.name;
}
Flow is a static type checker for JavaScript.
A transpiler from Java to TypeScript/JavaScript
A delightful language for reliable webapps.
PS: We are hiring!