Show Menu

Notizen zu Typescript Cheat Sheet by

Notizen zu Typescript - eher für Anfänger
typescript

Overlo­ading von Funkti­ons­sig­naturen

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 Bindun­gsarten

[xxx]
@Input
Input Parameter
(xxx)
@Output
Callback Parameter
 

Condit­ional 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);

Download the Notizen zu Typescript Cheat Sheet

1 Page
//media.cheatography.com/storage/thumb/funthomas424242_notizen-zu-typescript.750.jpg

PDF (recommended)

Alternative Downloads

Share This Cheat Sheet!

 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          jian's typescript best practices Cheat Sheet
          Mit Javascript unter Node.js entwickeln Cheat Sheet

          More Cheat Sheets by FunThomas424242

          Spring Boot Cheat Sheet