TypeScript
Version vom 14. August 2021, 14:09 Uhr von Hamatoma (Diskussion | Beiträge) (Die Seite wurde neu angelegt: „= Links = * Angular = Konstanten, Variablen = * 'var'-Variablen sind global, 'let'-Variablen sind lokal (blockgebunden). <source lang="ts"> const E_DISK:…“)
Links
Konstanten, Variablen
- 'var'-Variablen sind global, 'let'-Variablen sind lokal (blockgebunden).
const E_DISK: string = 'disk error';
var globalLastMessage: string = 'Error';
for (let i=0; i < 4; i++){}
const myArray = [ 0, 'string', { firstname: 'Joe' } ];
const onlyNumbers: number[] = [ 1, 2, 3];
let arg: any = 5; ... arg = 'string';
Typen
String
let x ='Hi';
x = `2 lines:
Say: ${x}
`;
Number
Any
Klassen
- Nur ein Konstruktor
class User {
publicItems: string;
private privateMember: string = 'secret';
private privateNumber = 25; // impliziter Typ.
constructor(items: string){
this.privateItems = items;
}
append(item: string): string { this.publicItems += ';' + item; return this.publicItems; }
// getter + setter:
get currentNumber(): number { return this.privateNumber; }
set number(value: number): void { this.privateNumber = value; }
add(inc: number) => return privateNumber + number;
}
class SuperUser extends User {
constructor(items: string){
super(items);
}
}
Interfaces
interface Contact {
firstname: string;
lastname: string;
}
const contact: Contact = {
firstname: 'Joe',
lastname: 'Doo'
}
class Address implements Contact {
firstname = 'Eve';
lastname = 'Smith';
}