TypeScript rocks?! 16. Mai 2017 Tuan Dang-Schulz
JS sucks?! 21.11.2018
The Pain of JavaScript keine Typsicherheit Objektorientierung schwierig für Ungeübte Keine gute IDE Unterstützung schwer wartbar bei großen Projekten Typos werden bestraft 21.11.2018
Vorteile von TS gute und große IDE Unterstützung frühe Fehlererkennung geeignet für große Anwendungen sicheres Refactoring
Sitemap Fakten und Aufbau Funktionsweise live coding
TypeScript ~2012 von Anders Hejlsberg/Microsoft veröffentlich Version 2.3 (Stand Mai 2017) Open-Source (Apache-2.0) https://www.typescriptlang.org/ Platz 15 auf GitHub https://octoverse.github.com bekannteste Projekte Angular2 VS-Code TypeScript
Aufbau basiert auf Vorschlägen von ES6 statisches Typensystem Var vs. let vs. const primitive Datentypen string, number, Date, Array, any Enum
OOP Klassen Interfaces Vererbung Generics Konstruktor Felder Methoden private/public/protected Interfaces Vererbung Generics
Beispiel function Person(firstName) { this.firstName = firstName; } function Student(firstName, id) { Person.call(this, firstName); this.id = id; } Student.prototype = Object.create(Person.prototype); Student.prototype.constructor = Student; Student.prototype.partyHard = function () { return "PARTY"; } var student = new Student("Bob", 12); alert(student.firstName + ": " + student.id + " - " + student.partyHard()); class Person{ constructor(public firstName:string) { } } class Stundent extends Person{ constructor(firstName:string, public readonly id:string) { super(firstName); } partHard() { return "Party"; } } const student = new Stundent("Bob", "ID42"); alert(student.partHard() + " ID:" + student.id); Beispiel einer Klassen Defnition Links JS mit Prototypen 21.11.2018
Async/Await async function doSomething() { try { let val = await getAPromise(); console.log(val); } catch(err) { console.log('Error: ', err.message); } } Lambda -> Arrow Functions in es6 -> this
Yield/Generator function* infinity() { let i = 0; while(true) { yield i++; } } var iterator = infinity(); interator.next(); Lambda -> Arrow Functions in es6 -> this
Anbindung externe Libs npm Ökosystem nutzbar DefinitelyTyped (*.d.ts) http://definitelytyped.org/ npm install lodash npm install --save @types/lodash
Vielen Dank für Ihre Aufmerksamkeit Ende Vielen Dank für Ihre Aufmerksamkeit 21.11.2018
Quellen https://basarat.gitbooks.io/typescript/content/docs/getting-started.html https://www.typescriptlang.org/ https://www.typescriptlang.org/play http://definitelytyped.org/ https://octoverse.github.com https://risingstars2016.js.org/ 21.11.2018
Abstract So gut wie jeder Softwareentwickler hat bestimmt schon mal über JavaScript geflucht. Es ist nicht typsicher, zu dynamisch, zu fehleranfällig und vieles mehr. Für diese Probleme hat Microsoft TypeScript entwickelt. Eine Objekt orientierte Sprache die jeder C#-Entwickler schnell erlernen und sicher anwenden kann, aber auch JavaScript Entwickler können auf ihr erlerntes Wissen zurückgreifen. In dem Vortrag möchte ich euch einen Einblick in die Sprache geben und aufzeigen, was die Sprache so interessant macht.
Kontakt zu uns... Wir navigieren erfolgreich zum Ziel. Tuan Dang-Schulz Software Developer Telefon +49 511 936206-37 E-Mail tdz@inwerken.de www.inwerken.de 21.11.2018