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

Angular Important

TypeScript, developed by Microsoft, enhances JavaScript by adding optional strong static typing, which helps catch errors early in the development process. It is a non-proprietary language that can be used anywhere JavaScript runs, offering benefits like less error-prone code and improved performance. The document also covers TypeScript's data types, destructuring, and features like Maps and Sets, while briefly mentioning Angular's capabilities.

Uploaded by

Areeba Khan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
426 views

Angular Important

TypeScript, developed by Microsoft, enhances JavaScript by adding optional strong static typing, which helps catch errors early in the development process. It is a non-proprietary language that can be used anywhere JavaScript runs, offering benefits like less error-prone code and improved performance. The document also covers TypeScript's data types, destructuring, and features like Maps and Sets, while briefly mentioning Angular's capabilities.

Uploaded by

Areeba Khan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 28
TypeScript is a programming language powered by Microsoft. TypeScript offers help adding types to Javascript so that one can easily catch the errors even before running the program, eventually speeding the development of JavaScript code. TypeScript is a non-proprietary programming language that runs on top of JavaScript. One can use it on any Website, operating system, or anywhere JavaScript is running. 1.3 BENEFITS OF TYPESCRIPT TypeScript offers several benefits 10 developers. Some of these are listed as follows 1) Strict Typing TypeScript introduces optional strong static typing: Once declared, a variable does not change its type and can take only certain values. This means that as and when type- related errors occur, developers will be notified by the compiler. This will ensure that errors do not cary forward to the production phase. The outcome of this is less error-prone code and improved performance during code execution. Installing Typescript TypeScript can be installed through npm. npm install TypeScript --save-dev The command will help to install the TypeScript compiler either globally or in the ‘workspace fo franspile TypeScript source code to JavaScript To verity the version that has been installed, before going ahead, one can type: tsc -v The result would be similar to this (which may differ depending on the actual version installed): Version 4.8 Number Number can be used to. Yepresent both integers ond fractions. let decimalhum: number= GF let hexwum: number— Oxf00ds let binarylum: number= ObLoi0, Jet octaiNum: number= dova47 Jet _bigNum: bigint= 100n7 ‘con held any data. When o voriabie type isnot Given ond Typescript cannot Inter its type from the inifiazzation then, H wil be treated as cn any type. Shing Sting data type & used 10 Tet newtessage=" Fitst store textual Gata. The String itera is enciosed In ["] GOUBIE quotes or [| single quotes. ‘Boolean Booleans in Typescript wore | TSC ISComplete? Booleaa= simiar to how iney do In false: Javaserpt. The mest basic datatype & the senple froe/tene valve. Enum Enum & a data type that enum Birection 1 Inclucies asc! oPnamedt Up, values. Generally, the names | Down, Constants, Right let go! Directio: go- bsrection.Upy Void Thi Gola hype & used in function showMessage()? void fonctions thatdonotrotum |i --- 1 ‘ony vaive.. Wot Nulindicates ne value. wall | iet nulivel? pull= nelle keyword & used to declare variables of this type. Such Variabies con ibe assignect ‘Only e.nul value Undefined | Gne can use the undefined | let undefineavai: undefined Types keyword asa data type to undefined? store the valve undefined to It. ey Any a special date type that | let notTrusted? anv= a7 (idefined as any RotTrusted= “maybe a number instead"? netTrusted= false: Tet stiliNotTrusted //No {Piype specified. inferred as any StillNotTrusted="may be a stiliNottrusted=false, Never Typascrint intraduced anew | fanctien doanything 1)? never type never, which indicates | 1 the values that wal never throw new Error("Error has occur. One canusetasthe | oecurred™)z return type of a function which | 9 does nol retun o valve, aney ‘An array is a type to | Awayscanbe defined im hno ifferent represent a set of ways. The fist isto use the brackets values belonging to slam fl. css totlows: homogeneous (same) Ter lise: mumberti= (1, 2, types. aie This tine of code tells Typescript that ‘the array shoul have only numbers. The other way is to use a generic type, speciically Aszaycrype>. the Jet list: Array= (1, 2, 319 Ihs tne of code 100 tells Typescript ‘hat the array should have only numbers, Tupie The Tupi bo dala type thot | // Declare a tuple Includes wo ormercsatsot | tet ar (string, sumber) + values of citferent dalatypes. | // tnitialize it Watows uxtoexprem ananey | S- ("Ein 8] where the type of a fixect but they are not the some. Data Types in typescript Tabie ‘Multiple Line Arrow Function For multiple line arrow functions, appropriate parentheses and multiple parameters can be used as shown in Code Snippet 17. Code Snippet 17 let addt (: number, y:number let z=5; return (xty+z)7} et result= adit (2,4); console.log (result); 1.10 DESTRUCTURING Destructuring means extracting the items only what is required. TypeScript supports Destructuring as a feature of breaking an existing structure. The simplest explanation for destructuring is to unpack values from amays, or properties from objects, into distinct variabies. There are two major categories of destructuring: 1, Object Destructuring 2. Array Destructuring Array Destructuring Array destructuring is a way of copying items into a variable without modifying the array. This is as shown in Code Snippet 21. 1.11MAP AND SET IN TYPESCRIPT ‘Map in TypeScript ‘Map allows developers to map keys to values without the disadvantages of using Objects. mapsgetil Ramewas an entry trom ‘Stan entry ihe saan trove the Mae Gate et in TypeScript Sets are similar to maps although they only keep keys not key-value pairs. They are well known in several other programming languages, however, are a new feature to JavaScript in ES 6. Enables jo add valves inthe S01 mySet= new SoE(): ‘Mobile Phone! hs Bet sacl set ada|tipnana'|y The adie) method & otto cnainabie, os seen Enables to inspect Stience of exe in Dewelopers.can check @ valve i present fifties set ox shou here: console-log Set has ¢*iPhone's Removes a value from the Set Values Con ibe erase fom me ser using deletes method: @ property tnot rohura sie of Sat Cleon the onthe set Developer can check ihe number oF seni in Thee Sart By Using) hae Sl nett shown hace consoleleg tmySer.sizels sf 2 Developers con claer the entra sat By using Sleae mathod a= thown here! mySet clear () console.loq (mySet.sizels // 9 Angutar 2 ©) Milter ecikety in Fypesenot jan opensource Brogrammeng lorguaiee semich io suport oF Soraserint ond buscs On H by Occang syntas ter ype cecewatiors) va-2088 Staines bugs fame Sha Inmocuces Etepeiient tor making HIF Request. Wzenciient o wale. oaste to Ux one mare powerlsl Worany = Spas ior pogesike Web ops a Burd Spitniner complet” knprowernants. cond Etprovomentr semiteds to. Atteria Goan November |, [+ Sanguiserhtep & ctepeccuhed i Anan snot s Bore Bnd hah bean neplased wan Sancuiarrcommen/ntep “Wren. AnguEr Sommonctine ofertas Icuy vhs wl Angier Mey 4 2008 = Saeee Ta [= tien smned cng wih Angwer CU F ara sot sais ipso tacnecicn 9 one Moy 2.78 [> he Scien wat) ARGAGE GLTBGAS ARS 2 hioves o8 GSpsCGTOn: Ta uae Wy Comemer Grd Angeion # Fenny furiinme ty atau, anguior hay been updated soa So wert wit Tymescrigt te cing 3.7 a Roverser [= Aulomatc inining of tons, siicat tees Gnd sao Tae Seas peter Roger [amor Es 12 GT [= este ir erosing ronserions oT interns Expiorer [I] & romaverd Irom ihe Anau Seamyssem pwoants |Neremmer |. Se Nts Webs apy for_umeng mower feolurer nah ot Wet anmations ond CSS Angutor 14 2.3.2 Features of Angular Some of the features of Angular are as follows: Angular uses two-way data binding which means that any modifications made Uiiesk 2c tothe associated Ul components are reflected in the model state and UI state, ae) ‘on the other hand, changes in the model state. Angular connects the DOM io the model data via the controller using data binding. eee ubt de) ) Angular 14 offers developers a solid platform to build single-page client HTML, ‘TypeScript. Angular 14 provides essential noctuidess Nek) G goirul lene ee Ba Combes as wonptae es oat apps. eee ae ee eeu) eee en is bos ats bol coe Reese ee ‘use device apecitic oe a ele eeee eeee Peels @ part of the document. Angular makes use of ‘DOM, Ce aud Geadera son ch eigen nde’ ae page. Resear Angular will date he tree structure of HTML tage, utes unjust Neck) Angular extends HTML to give it MVC capabilities. MVC is a 0 Caner haste sestier as kaos eer meres et ec framework Goran) Ragas testing framework: creating test scenarios Sa eer — "

You might also like