0% found this document useful (0 votes)
65 views

TypeScript CheatSheet

TypeScript CheatSheet

Uploaded by

fgilfillan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
65 views

TypeScript CheatSheet

TypeScript CheatSheet

Uploaded by

fgilfillan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 9
TypeScript Cheatsheet Basic Types [ae index.ts // numeric data type aS mer V2- TL a // string data type let name: string = ‘John'; // boolean data type let isDone: boolean = false; Omni Keke Kol me cna Tama function foo(): void { console. log('Hello, world!'); i US ert acl ee ET let x: any = 42; P/Ae Mens ha aot) let nullValue: null = null; PAU amet eM 819 AU COOmUTATo (hme Oal-Lo NMA TEM io(-n mea at -Lo EMT o(hab A at -X0 7 Saad Irfan _) @DevWithSaad Function ” zw ord cron) Peas Os Cee eee function add(a: number, b: number): number { eet 1 77 Meas Ce Ts Ce cd eC arueess Uren console.log( “Hello, ${name 7 ‘world’ } i este eee function repeat(text: string, times: number = 3): string { Retreat est oot rp Tees een od Sas CIE Geen LCE) L248 DE Sa Sree eea iG 1 See cc CLE Hf east eat eur SCI acer Cress ste Tay ese ace eau a ees Ure} Riese adele teas suc Eros Cr ma ptaes mC “string') { return parseInt(value, 10); ene return value.toString(); + E Saad Irfan @DevWithSaad Interfaces eoe eon Vee Come aA Sato) pee es name: string; age: number; a // 2. Interface with optional property Bae eo a BT ae email?: string; I // 3. Interface with readonly property interface Point { PEIN eee tsa readonly y: number; y ree Uae ee ee ae ota) Sia era el Lag add(a: number, b: number): number; } Saad Irfan D @DevwithSaad Interfaces (Cont) Cr oa ome ace ee ee ee aL aE e a NT eet Cee ee department: string; i ere ee See Sie sae TST draw(): void; } Ste sae eae A ae TL Cee TM EMU Loar rete rem a » eee Ce eS eT) eae aes eae (key: string]: T; a ee Uae ee a ET Lab) St Sas oa (CrLCPaS SC eee site a & Saad Irfan Ps SLM cel See ee eS Saad Irfan < Ds SoM) Type Assertion OO irony CULTS a ee eee Teen Cap Ea) esas eu Pau eC ees Pec u rer een let Length2: number = (name2 as string).length; ae Cm me EC let value: string | number = '42'; iran ee at Se Cra sucer rin om cay) eee es eu ast) 7 ao UR LCL SUI ee Ce een sa ed tee UE oS Le ae Deere Cee nee on San eee Ue caer CU ease ees scr let user: { id: number; name: string } | null = { id: 42, name: if (user == null) { TOaE Eos uae ee uh 7 Saad Irfan 7 @DevWithSaad PT Classes ood ot) aoe Cee esa Tey class Person { Seatac CMe rarest Me ieee eee eee aT SOs getrultName(): string { return “${this.firstName} ${this-lastNane}”; i} } mate usted Sree secant Ciaatao ties stead Cees ier Ce gecees oT SC reo Sere Coca iy Pots ermacsu at return “${this.getFuliName()}, Agi one one soe Cee osc ay y i ao eC ace? Creare scr private salary: number; Cetera UC ester ee eee Sea OS Tee Coen this.salary = salary; n Pee are ea ane Pec ireren eta i y & Saad Irfan ae Ds oleae) Did You Find it Useful? : Alamin CodePapa | i @CodePapa360 Like Comment Repost Caen nc.

You might also like