SlideShare a Scribd company logo
Beginner to Advanced
TYPESCRIPT
Swamiprasad Amin
Prabhu Yadav
Shashank Korthiwada
Sachin Sahu
What is Typescript?
 A strict syntactical superset of JavaScript, which adds type-safety to the JS
code.
 Free and open-source programming language developed and maintained by
Microsoft.
 It doesn’t change the runtime behaviour of JS.
2
Why Typescript?
3
Why Typescript?
 It has the potential to move some kinds of errors from runtime to compile time.
Examples include
- Potentially absent values
- Incomplete Refactoring
 It serves as the foundation for a great code authoring experience.
Note:
• Only activate during development
• Doesn't provide any performance optimization
• In some other languages the type system can be used to optimize some code
that we write using the compiler.
4
Typescript Installation
 Node.js should be installed
 npm install Typescript
 To compile a Typescript file
 npx tsc <filename>
 It catches type errors in the Typescript file and creates a JavaScript file
with the same name.
5
Type Systems
Static vs dynamic
• whether type-checking is performed at compile time or runtime.
Nominal vs structural
• Nominal type systems are all about NAMES, two types are deemed to be the
same if they have the same name
• Structural type systems are all about STRUCTURE or SHAPE
TypeScript’s type system is static.
TypeScript's type system is structural
6
Type Annotations
• Typescript uses type annotation to specify the data type of the variable, function,
object, or function return value.
• It uses the syntax :[type], where type is the Typescript type.
7
Primitive types
The Primitives: String, Number, Boolean
• string represents string values like "Hello, world"
• number is for numbers like 42. JavaScript does not have a special runtime value
for integers, so there’s no equivalent to int or float - everything is simply number
• boolean is for the two values true and false
• It has some special types too unknown, any, void & never.
Literal Types
In addition to the general types string and number, we can refer to specific strings and
numbers in type positions
Enums
Allows for describing a value which could be one of a set of possible named constants.
8
Union Types
 TypeScript’s type system allows us to build new types out of existing ones using a
large variety of operators.
 We can achieve different use cases by combining types in interesting ways.
 Syntax:
We define union types by using a pipe (|) to separate each of the possible types
(type1 | type2 | type3 | .. | typeN)
9
Type Aliases and Interfaces
 TypeScript provides two mechanisms for centrally defining types and giving them
useful and meaningful names
• Interfaces
• type aliases
 Type aliases allows us to
• define a more meaningful name for this type
• declare the particulars of the type in a single place
• import and export this type from modules, the same as if it were an exported
value
 An interface is a way of defining an object type.
• Like type aliases, interfaces can be imported/exported between modules
10
Objects
 Anything that is not a primitive data type is a Typescript object.
 It is a collection of key-value pairs.
 Each key-value pair is known as a property, where the key is the name of the
property and value its value.
 These provide a way to group several values into a single value.
 Few ways on how types are associated for Objects
• Object Literal Syntax
• Named Types using Type Aliases and Interfaces
11
Arrays
 Syntax for typing an array is Type[] or Array<Type>.
 Here, Type can be combination of types.
e.g. const list: (string | number)[] = [10, "twenty"]
Tuple:
 Sometimes we may want to work with a multi-element, ordered data structure, where
position of each item has some special meaning or convention.
e.g. type StringNumberPair = [string, number]
 It can have optional properties and they come at the end.
 A tuple with a rest element has no set “length” - it only has a set of well-known elements in
different positions.
 Tuples tend to be created and left un-modified in most code.
12
Functions
 The syntax (param: string) => void means “a function with one parameter,
named param, of type string, that doesn’t have a return value”.
 Optional parameters can be typed with ?.
 void is not the same as undefined.
 When writing a function type for a callback, marking a parameter optional should be
avoided unless it is intended to call the function without passing that argument.
 A function, that can be called in different ways, can be typed by writing overload
signatures.
 If this is not inferred from code-flow analysis, it can be typed.
 unknown is the type-safe counterpart of any.
 The type annotation on rest parameters is implicitly any[].
13
Classes
 Fields of class can be typed and/or initialized.
e.g. class Point { x: number, y = 0 }
 Class constructors are very similar to functions. But, it doesn't have a return type
annotation.
 super must be called before accessing this in the constructor of a derived
class.
 implements clause is to check that a class satisfies a particular interface.
 Derived classes need to follow their base class contracts. But it may choose to
expose a subtype of base class with more capabilities.
 Soft-private allows access using bracket notation.
14
Generics
A kind of tool that enables you to create reusable code components that
work with a number of types instead of a single type.
<Type> parameters are for relating the types of multiple values.
Type parameters can be constrained with extends keyword.
Benefits:
 Defining a relationship between input and output parameters types.
e.g. Utility Functions
 Stronger type checks at compile time will be available.
 You can remove some unnecessary type casts.
 You may leave type variable unassigned.
15
<T>
Utility Types
Globally available types to facilitate common type
transformations.
Benefits:
 These types are themselves strongly typed and has specific
use cases.
e.g. Parameters<T>, here T extends (...args: any) => any
 Saves time of creating custom types for day-to-day type
manipulations.
 Saves you from having to think about naming your utilities.
16
Pick x Omit
Readonly
ReturnType
NonNullable
Required x Partial
Extract x Extract
Parameters
Record
Type Manipulation
 Conditional types let us deterministically define type transformations depending on a
condition.
 A ternary conditional operator applied at the type level rather than at the value level.
17
 Mapped types are useful when there is a need for a type to be derived from (and
remain in sync with) another type.
 Helps us keep our types definitions that are dependent on each other code in DRY
state.
Conditional Types
Mapped Types
Decorators
 A Decorator is a special kind of declaration that can be attached to a class
declaration, method, accessor, property or parameter.
 Decorators provide a way to add both annotations and a meta-programming
syntax for class declarations and members.
 Decorators are a stage 2 proposal for JavaScript and are available as an
experimental feature of TypeScript.
 To enable experimental support for decorators, you must enable the
experimentalDecorators compiler option either on the command line or in
your tsconfig.json
18
THANK YOU
Ad

More Related Content

What's hot (20)

TypeScript Presentation
TypeScript PresentationTypeScript Presentation
TypeScript Presentation
Patrick John Pacaña
 
TypeScript
TypeScriptTypeScript
TypeScript
Saray Chak
 
TypeScript intro
TypeScript introTypeScript intro
TypeScript intro
Ats Uiboupin
 
TypeScript Overview
TypeScript OverviewTypeScript Overview
TypeScript Overview
Aniruddha Chakrabarti
 
Introducing type script
Introducing type scriptIntroducing type script
Introducing type script
Remo Jansen
 
TypeScript - An Introduction
TypeScript - An IntroductionTypeScript - An Introduction
TypeScript - An Introduction
NexThoughts Technologies
 
Getting started with typescript
Getting started with typescriptGetting started with typescript
Getting started with typescript
C...L, NESPRESSO, WAFAASSURANCE, SOFRECOM ORANGE
 
Typescript Fundamentals
Typescript FundamentalsTypescript Fundamentals
Typescript Fundamentals
Sunny Sharma
 
Typescript in 30mins
Typescript in 30mins Typescript in 30mins
Typescript in 30mins
Udaya Kumar
 
Typescript overview
Typescript overviewTypescript overview
Typescript overview
Thanvilahari
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
Dmitry Sheiko
 
TypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the painTypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the pain
Sander Mak (@Sander_Mak)
 
TypeScript: Basic Features and Compilation Guide
TypeScript: Basic Features and Compilation GuideTypeScript: Basic Features and Compilation Guide
TypeScript: Basic Features and Compilation Guide
Nascenia IT
 
TypeScript Best Practices
TypeScript Best PracticesTypeScript Best Practices
TypeScript Best Practices
felixbillon
 
TypeScript
TypeScriptTypeScript
TypeScript
Udaiappa Ramachandran
 
Why TypeScript?
Why TypeScript?Why TypeScript?
Why TypeScript?
FITC
 
Coding standards and guidelines
Coding standards and guidelinesCoding standards and guidelines
Coding standards and guidelines
brijraj_singh
 
java interface and packages
java interface and packagesjava interface and packages
java interface and packages
VINOTH R
 
Classes and Objects in C#
Classes and Objects in C#Classes and Objects in C#
Classes and Objects in C#
Adeel Rasheed
 
Packages,static,this keyword in java
Packages,static,this keyword in javaPackages,static,this keyword in java
Packages,static,this keyword in java
Vishnu Suresh
 

Similar to Typescript: Beginner to Advanced (20)

typescript.pptx
typescript.pptxtypescript.pptx
typescript.pptx
ZeynepOtu
 
TypeScript Interview Questions PDF By ScholarHat
TypeScript Interview Questions PDF By ScholarHatTypeScript Interview Questions PDF By ScholarHat
TypeScript Interview Questions PDF By ScholarHat
Scholarhat
 
TypeScript.ppt LPU Notes Lecture PPT for 2024
TypeScript.ppt  LPU Notes Lecture PPT for 2024TypeScript.ppt  LPU Notes Lecture PPT for 2024
TypeScript.ppt LPU Notes Lecture PPT for 2024
manveersingh2k05
 
Data Handling
Data HandlingData Handling
Data Handling
Praveen M Jigajinni
 
LEARN C# PROGRAMMING WITH GMT
LEARN C# PROGRAMMING WITH GMTLEARN C# PROGRAMMING WITH GMT
LEARN C# PROGRAMMING WITH GMT
Tabassum Ghulame Mustafa
 
Typescript
TypescriptTypescript
Typescript
Nikhil Thomas
 
Type system
Type systemType system
Type system
baabtra.com - No. 1 supplier of quality freshers
 
Notes(1).pptx
Notes(1).pptxNotes(1).pptx
Notes(1).pptx
InfinityWorld3
 
C#
C#C#
C#
Sudhriti Gupta
 
Static abstract members nelle interfacce di C# 11 e dintorni di .NET 7.pptx
Static abstract members nelle interfacce di C# 11 e dintorni di .NET 7.pptxStatic abstract members nelle interfacce di C# 11 e dintorni di .NET 7.pptx
Static abstract members nelle interfacce di C# 11 e dintorni di .NET 7.pptx
Marco Parenzan
 
Data Types in C++-Primary or Built-in or Fundamental data type Derived data t...
Data Types in C++-Primary or Built-in or Fundamental data type Derived data t...Data Types in C++-Primary or Built-in or Fundamental data type Derived data t...
Data Types in C++-Primary or Built-in or Fundamental data type Derived data t...
ssuser5610081
 
Concept of c data types
Concept of c data typesConcept of c data types
Concept of c data types
Manisha Keim
 
2.Getting Started with C#.Net-(C#)
2.Getting Started with C#.Net-(C#)2.Getting Started with C#.Net-(C#)
2.Getting Started with C#.Net-(C#)
Shoaib Ghachi
 
Introduction to C#
Introduction to C#Introduction to C#
Introduction to C#
Raghuveer Guthikonda
 
Learning typescript
Learning typescriptLearning typescript
Learning typescript
Alexandre Marreiros
 
C#ppt
C#pptC#ppt
C#ppt
Sambasivarao Kurakula
 
Generics
GenericsGenerics
Generics
Sankar Balasubramanian
 
Unit 1 question and answer
Unit 1 question and answerUnit 1 question and answer
Unit 1 question and answer
Vasuki Ramasamy
 
CSharp for Unity Day 3
CSharp for Unity Day 3CSharp for Unity Day 3
CSharp for Unity Day 3
Duong Thanh
 
More Little Wonders of C#/.NET
More Little Wonders of C#/.NETMore Little Wonders of C#/.NET
More Little Wonders of C#/.NET
BlackRabbitCoder
 
Ad

More from Talentica Software (20)

Webpack/Parcel: What’s Happening Behind the React App?
Webpack/Parcel: What’s Happening Behind the React App?Webpack/Parcel: What’s Happening Behind the React App?
Webpack/Parcel: What’s Happening Behind the React App?
Talentica Software
 
Web 3.0
Web 3.0Web 3.0
Web 3.0
Talentica Software
 
Remix
RemixRemix
Remix
Talentica Software
 
Web Performance & Latest in React
Web Performance & Latest in ReactWeb Performance & Latest in React
Web Performance & Latest in React
Talentica Software
 
Nodejs Chapter 3 - Design Pattern
Nodejs Chapter 3 - Design PatternNodejs Chapter 3 - Design Pattern
Nodejs Chapter 3 - Design Pattern
Talentica Software
 
Node js Chapter-2
Node js Chapter-2Node js Chapter-2
Node js Chapter-2
Talentica Software
 
Node.js Chapter1
Node.js Chapter1Node.js Chapter1
Node.js Chapter1
Talentica Software
 
Micro Frontends
Micro FrontendsMicro Frontends
Micro Frontends
Talentica Software
 
Test Policy and Practices
Test Policy and PracticesTest Policy and Practices
Test Policy and Practices
Talentica Software
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
Talentica Software
 
Setting Up Development Environment For Google App Engine & Python | Talentica
Setting Up Development Environment For Google App Engine & Python | TalenticaSetting Up Development Environment For Google App Engine & Python | Talentica
Setting Up Development Environment For Google App Engine & Python | Talentica
Talentica Software
 
Connected World in android - Local data sharing and service discovery
Connected World in android - Local data sharing and service discoveryConnected World in android - Local data sharing and service discovery
Connected World in android - Local data sharing and service discovery
Talentica Software
 
Mobile App Monetization - Ecosystem & Emerging Trends
Mobile App Monetization - Ecosystem & Emerging TrendsMobile App Monetization - Ecosystem & Emerging Trends
Mobile App Monetization - Ecosystem & Emerging Trends
Talentica Software
 
Android Media Player Development
Android Media Player DevelopmentAndroid Media Player Development
Android Media Player Development
Talentica Software
 
Cross Platform Mobile Technologies
Cross Platform Mobile TechnologiesCross Platform Mobile Technologies
Cross Platform Mobile Technologies
Talentica Software
 
Big Data Technologies - Hadoop
Big Data Technologies - HadoopBig Data Technologies - Hadoop
Big Data Technologies - Hadoop
Talentica Software
 
Big Data – Are You Ready?
Big Data – Are You Ready?Big Data – Are You Ready?
Big Data – Are You Ready?
Talentica Software
 
Legacy modernization
Legacy modernizationLegacy modernization
Legacy modernization
Talentica Software
 
Continous Integration: A Case Study
Continous Integration: A Case StudyContinous Integration: A Case Study
Continous Integration: A Case Study
Talentica Software
 
Technology Challenges in Building New Media Applications
Technology Challenges in Building New Media ApplicationsTechnology Challenges in Building New Media Applications
Technology Challenges in Building New Media Applications
Talentica Software
 
Webpack/Parcel: What’s Happening Behind the React App?
Webpack/Parcel: What’s Happening Behind the React App?Webpack/Parcel: What’s Happening Behind the React App?
Webpack/Parcel: What’s Happening Behind the React App?
Talentica Software
 
Web Performance & Latest in React
Web Performance & Latest in ReactWeb Performance & Latest in React
Web Performance & Latest in React
Talentica Software
 
Nodejs Chapter 3 - Design Pattern
Nodejs Chapter 3 - Design PatternNodejs Chapter 3 - Design Pattern
Nodejs Chapter 3 - Design Pattern
Talentica Software
 
Setting Up Development Environment For Google App Engine & Python | Talentica
Setting Up Development Environment For Google App Engine & Python | TalenticaSetting Up Development Environment For Google App Engine & Python | Talentica
Setting Up Development Environment For Google App Engine & Python | Talentica
Talentica Software
 
Connected World in android - Local data sharing and service discovery
Connected World in android - Local data sharing and service discoveryConnected World in android - Local data sharing and service discovery
Connected World in android - Local data sharing and service discovery
Talentica Software
 
Mobile App Monetization - Ecosystem & Emerging Trends
Mobile App Monetization - Ecosystem & Emerging TrendsMobile App Monetization - Ecosystem & Emerging Trends
Mobile App Monetization - Ecosystem & Emerging Trends
Talentica Software
 
Android Media Player Development
Android Media Player DevelopmentAndroid Media Player Development
Android Media Player Development
Talentica Software
 
Cross Platform Mobile Technologies
Cross Platform Mobile TechnologiesCross Platform Mobile Technologies
Cross Platform Mobile Technologies
Talentica Software
 
Big Data Technologies - Hadoop
Big Data Technologies - HadoopBig Data Technologies - Hadoop
Big Data Technologies - Hadoop
Talentica Software
 
Continous Integration: A Case Study
Continous Integration: A Case StudyContinous Integration: A Case Study
Continous Integration: A Case Study
Talentica Software
 
Technology Challenges in Building New Media Applications
Technology Challenges in Building New Media ApplicationsTechnology Challenges in Building New Media Applications
Technology Challenges in Building New Media Applications
Talentica Software
 
Ad

Recently uploaded (20)

Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 

Typescript: Beginner to Advanced

  • 1. Beginner to Advanced TYPESCRIPT Swamiprasad Amin Prabhu Yadav Shashank Korthiwada Sachin Sahu
  • 2. What is Typescript?  A strict syntactical superset of JavaScript, which adds type-safety to the JS code.  Free and open-source programming language developed and maintained by Microsoft.  It doesn’t change the runtime behaviour of JS. 2
  • 4. Why Typescript?  It has the potential to move some kinds of errors from runtime to compile time. Examples include - Potentially absent values - Incomplete Refactoring  It serves as the foundation for a great code authoring experience. Note: • Only activate during development • Doesn't provide any performance optimization • In some other languages the type system can be used to optimize some code that we write using the compiler. 4
  • 5. Typescript Installation  Node.js should be installed  npm install Typescript  To compile a Typescript file  npx tsc <filename>  It catches type errors in the Typescript file and creates a JavaScript file with the same name. 5
  • 6. Type Systems Static vs dynamic • whether type-checking is performed at compile time or runtime. Nominal vs structural • Nominal type systems are all about NAMES, two types are deemed to be the same if they have the same name • Structural type systems are all about STRUCTURE or SHAPE TypeScript’s type system is static. TypeScript's type system is structural 6
  • 7. Type Annotations • Typescript uses type annotation to specify the data type of the variable, function, object, or function return value. • It uses the syntax :[type], where type is the Typescript type. 7
  • 8. Primitive types The Primitives: String, Number, Boolean • string represents string values like "Hello, world" • number is for numbers like 42. JavaScript does not have a special runtime value for integers, so there’s no equivalent to int or float - everything is simply number • boolean is for the two values true and false • It has some special types too unknown, any, void & never. Literal Types In addition to the general types string and number, we can refer to specific strings and numbers in type positions Enums Allows for describing a value which could be one of a set of possible named constants. 8
  • 9. Union Types  TypeScript’s type system allows us to build new types out of existing ones using a large variety of operators.  We can achieve different use cases by combining types in interesting ways.  Syntax: We define union types by using a pipe (|) to separate each of the possible types (type1 | type2 | type3 | .. | typeN) 9
  • 10. Type Aliases and Interfaces  TypeScript provides two mechanisms for centrally defining types and giving them useful and meaningful names • Interfaces • type aliases  Type aliases allows us to • define a more meaningful name for this type • declare the particulars of the type in a single place • import and export this type from modules, the same as if it were an exported value  An interface is a way of defining an object type. • Like type aliases, interfaces can be imported/exported between modules 10
  • 11. Objects  Anything that is not a primitive data type is a Typescript object.  It is a collection of key-value pairs.  Each key-value pair is known as a property, where the key is the name of the property and value its value.  These provide a way to group several values into a single value.  Few ways on how types are associated for Objects • Object Literal Syntax • Named Types using Type Aliases and Interfaces 11
  • 12. Arrays  Syntax for typing an array is Type[] or Array<Type>.  Here, Type can be combination of types. e.g. const list: (string | number)[] = [10, "twenty"] Tuple:  Sometimes we may want to work with a multi-element, ordered data structure, where position of each item has some special meaning or convention. e.g. type StringNumberPair = [string, number]  It can have optional properties and they come at the end.  A tuple with a rest element has no set “length” - it only has a set of well-known elements in different positions.  Tuples tend to be created and left un-modified in most code. 12
  • 13. Functions  The syntax (param: string) => void means “a function with one parameter, named param, of type string, that doesn’t have a return value”.  Optional parameters can be typed with ?.  void is not the same as undefined.  When writing a function type for a callback, marking a parameter optional should be avoided unless it is intended to call the function without passing that argument.  A function, that can be called in different ways, can be typed by writing overload signatures.  If this is not inferred from code-flow analysis, it can be typed.  unknown is the type-safe counterpart of any.  The type annotation on rest parameters is implicitly any[]. 13
  • 14. Classes  Fields of class can be typed and/or initialized. e.g. class Point { x: number, y = 0 }  Class constructors are very similar to functions. But, it doesn't have a return type annotation.  super must be called before accessing this in the constructor of a derived class.  implements clause is to check that a class satisfies a particular interface.  Derived classes need to follow their base class contracts. But it may choose to expose a subtype of base class with more capabilities.  Soft-private allows access using bracket notation. 14
  • 15. Generics A kind of tool that enables you to create reusable code components that work with a number of types instead of a single type. <Type> parameters are for relating the types of multiple values. Type parameters can be constrained with extends keyword. Benefits:  Defining a relationship between input and output parameters types. e.g. Utility Functions  Stronger type checks at compile time will be available.  You can remove some unnecessary type casts.  You may leave type variable unassigned. 15 <T>
  • 16. Utility Types Globally available types to facilitate common type transformations. Benefits:  These types are themselves strongly typed and has specific use cases. e.g. Parameters<T>, here T extends (...args: any) => any  Saves time of creating custom types for day-to-day type manipulations.  Saves you from having to think about naming your utilities. 16 Pick x Omit Readonly ReturnType NonNullable Required x Partial Extract x Extract Parameters Record
  • 17. Type Manipulation  Conditional types let us deterministically define type transformations depending on a condition.  A ternary conditional operator applied at the type level rather than at the value level. 17  Mapped types are useful when there is a need for a type to be derived from (and remain in sync with) another type.  Helps us keep our types definitions that are dependent on each other code in DRY state. Conditional Types Mapped Types
  • 18. Decorators  A Decorator is a special kind of declaration that can be attached to a class declaration, method, accessor, property or parameter.  Decorators provide a way to add both annotations and a meta-programming syntax for class declarations and members.  Decorators are a stage 2 proposal for JavaScript and are available as an experimental feature of TypeScript.  To enable experimental support for decorators, you must enable the experimentalDecorators compiler option either on the command line or in your tsconfig.json 18