Cheatography
https://cheatography.com
Notizen zu Typescript - eher für Anfänger
Overloading von Funktionssignaturen
export class Test{
public add( a: Number, b:Number):void;
public add( a: String, b:String):void;
public add( a: boolean, b:boolean):void;
public add( a, b):void{
console.log(a+b);
}
public static run():any{
let t:Test = new Test();
t.add('a','b');
t.add(3,5);
t.add(true,true);
}
}
Test.run();
Erzeugt die Ausgaben:
ab
8
2
|
Typescript Bindungsarten
[xxx] |
@Input |
Input Parameter |
(xxx) |
@Output |
Callback Parameter |
|
|
Conditional Types
declare type StringOrNull<T> = T extends string
? string
: T extends null
? null
: never;
export function upperCase<T extends string | null>(text: T): StringOrNull<T>;
export function upperCase(text: string | null): string | null {
if (typeof text === 'string') {
return text.toUpperCase();
}
return null;
}
// String
upperCase('').toLocaleLowerCase();
// Null
upperCase(null);
// Union
let maybe: string | null = null as any;
upperCase(maybe);
|
|
Created By
https://github.com/Huluvu424242
Metadata
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets
More Cheat Sheets by FunThomas424242