SlideShare a Scribd company logo
TypeScript for
Java Developers
Yakov Fain

yfain
@yfain
About myself
• Work for Farata Systems
• Blogging at yakovfain.com
• Youtube channel “Карьера в ИТ”
Use the discount code 

tstsquick

at manning.com
@yfain
What’s TypeScript
• It’s a programming language that compiles to JavaScript
• It’s JavaScript + types + great IDE support
• It’s about catching errors during compile-time
• It’a superset of JavaScript
@yfain
StackOverflow Dev Survey 2020
Programming, Scripting, and Markup Languages
@yfain
StackOverflow Dev Survey 2020
Most loved
@yfain
let customerId = "A15BN"; // OK, customerId is a string
customerId = 123; // OK, from now on it's a number
JavaScript
@yfain
let customerId = "A15BN"; // OK, customerId is a string
customerId = 123; // OK, from now on it's a number
JavaScript
let customerId: string; // OK, customerId is a string
customerId = 123; // Compile-time error
TypeScript
@yfain
The Pythagorean Theorem
function distance(pointА, pointB) {
return Math.sqrt(
(pointА.x - pointB.x) ** 2 +
(pointА.y - pointB.y) ** 2);
}
console.log(distance({ z: 3, y: -4 }, {x:6, y:0}));
Playground: https://bit.ly/2vMUHKH
Anything wrong with this code?
@yfain
Typical workflow
@yfain
tsc compilation options
• All options are listed at https://bit.ly/1UYGHFp 

• For example, you can use the option target:



tsc main --target es5
• Alternative: create a file named tsconfig.json and specify
all compilation options there; then simply run



tsc
@yfain
Sample tsconfig.json
{
"compilerOptions": {
"outDir": "./dist",
"noEmitOnError": true,
"target": "es5"
}
}
tsc -init will generate tsconfig.json
TypeScript and IDEs
• Visual Studio Code (free)
• IntelliJ IDEA or WebStorm
• Sublime Text with TypeScript plugin
• Eclipse with TypeScript plugin
Installing the TypeScript compiler
1.Install Node.js from nodejs.org

2.Install TypeScript compiler globally:



npm i typescript -g

Installing the TypeScript compiler
1.Install Node.js from nodejs.org

2.Install TypeScript compiler globally:



npm i typescript -g

npm in JavaScript is like Maven in Java



npmjs.org is like maven central

let myName:string;
myName = "Yakov Fain";
console.log(`Hello ${myName}`);
tsc --t es5 hello.ts
1. Create a new file hello.ts
2. Compile hello.ts to hello.js (the ES5 flavor)
Compiling a script
Fat arrow functions

(similar to Java lambdas)
Fat arrow functions
Fat arrow function:
Anonymous function:
Fat arrow functions make
the meaning of the this
pointer predictable.
TypeScript Classes
and Inheritance
A class with constructor:take 1
A class with constructor: take 2
Inheritance
Classical syntax Prototypal
@yfain
Structural vs nominal type systems
• An object or class has a name and some structure
• In nominal type systems (e.g. Java), two types are the same
if they have the same names
• In structural type systems, two types are the same if they
have the similar structures.
@yfain
If it looks like a duck, swims like a
duck, and quacks like a duck, then it
probably is a duck
@yfain
class Person {
String name;
}
class Customer {
String name;
}
Customer cust = new Person(); // error
Java (nominal type system)
@yfain
class Person {
name: string;
}
class Customer {
name: string;
}
const cust: Customer = new Person(); // no errors
TypeScript (structural type system)
@yfain
class Person {
name: String;
}
class Customer {
name: String;
}
const cust: Customer = { name: 'Mary' };
const pers: Person = { name: 'John' };
Compatible types
@yfain
class Person {
name: String;
age: number;
}
class Customer {
name: String;
}
const cust: Customer = new Person(); // no errors
When classes are not the same
@yfain
class Person {
name: string;
}
class Customer {
name: string;
age: number;
}
const cust: Customer = new Person(); // error
When classes are not the same
Generics
Generics
Generics allow using parameterized types
Generics
No Errors - TypeScript uses structural typing, 

while Java uses the nominal one.
Interfaces
Interfaces as custom types
No interfaces
here
Implementing interfaces
A class implements a class
class ProductService {
saveProduct(productID:number): void{
// TODO: implement here
}
}
class MockProductService implements ProductService{
saveProduct(productId: number):void{
}
}
TypeScript Decorators

(think Java annotations)
What’s a Decorator?
• Decorator is a function with metadata about a
class, property, method or a parameter
• Decorators start with the @-sign, e.g.
@Component
A sample Angular component with
decorators
@Component({
selector: 'order-processor',
template: `
Buying {{quantity}} shares}
`
})
export class OrderComponent {
@Input() quantity: number;
}
Links
• My TypeScript video lessons and more:

https://www.youtube.com/c/YakovFain/playlists
• My blog:

yakovfain.com
• TypeScript docs and playground

https://www.typescriptlang.org/

More Related Content

PDF
Using JHipster for generating Angular/Spring Boot apps
PDF
Using JHipster for generating Angular/Spring Boot apps
PDF
Using JHipster 4 for generating Angular/Spring Boot apps
PDF
Intro to JavaScript
PDF
Angular 2 for Java Developers
PDF
Java Intro: Unit1. Hello World
PDF
Testing nightwatch, by David Torroija
PDF
Automated Testing in Angular Slides
Using JHipster for generating Angular/Spring Boot apps
Using JHipster for generating Angular/Spring Boot apps
Using JHipster 4 for generating Angular/Spring Boot apps
Intro to JavaScript
Angular 2 for Java Developers
Java Intro: Unit1. Hello World
Testing nightwatch, by David Torroija
Automated Testing in Angular Slides

What's hot (20)

PPTX
Why I am hooked on the future of React
PDF
Introduction to angular 4
PDF
RESTful services and OAUTH protocol in IoT
PDF
TypeScript for Java Developers
PDF
Intro To React Native
PDF
Nightwatch at Tilt
PDF
Node.js and Selenium Webdriver, a journey from the Java side
PDF
Node, express & sails
PDF
Front-End Testing: Demystified
PPTX
Nightwatch JS for End to End Tests
PDF
XebiConFr 15 - Brace yourselves Angular 2 is coming
PPT
Testing in AngularJS
ODP
Introduction to Angular 2
PDF
Up & running with ECMAScript6
PDF
Angular Application Testing
PPTX
Testing of React JS app
PPTX
Building Reliable Applications Using React, .NET & Azure
KEY
Agile JavaScript Testing
PDF
An Intro to Angular 2
Why I am hooked on the future of React
Introduction to angular 4
RESTful services and OAUTH protocol in IoT
TypeScript for Java Developers
Intro To React Native
Nightwatch at Tilt
Node.js and Selenium Webdriver, a journey from the Java side
Node, express & sails
Front-End Testing: Demystified
Nightwatch JS for End to End Tests
XebiConFr 15 - Brace yourselves Angular 2 is coming
Testing in AngularJS
Introduction to Angular 2
Up & running with ECMAScript6
Angular Application Testing
Testing of React JS app
Building Reliable Applications Using React, .NET & Azure
Agile JavaScript Testing
An Intro to Angular 2
Ad

Similar to Type script for_java_dev_jul_2020 (20)

PPTX
TypeScript: Basic Features and Compilation Guide
PPTX
Type script - advanced usage and practices
PPTX
Getting started with typescript
PDF
TypeScript: coding JavaScript without the pain
PPTX
The advantage of developing with TypeScript
PPTX
AngularConf2015
ODP
Getting started with typescript and angular 2
PPTX
Type script
PDF
An Introduction to TypeScript
PDF
Type script
PPTX
Typescript language extension of java script
PPTX
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
PPTX
TypeScript Introduction
PPTX
TypeScript . the JavaScript developer best friend!
PDF
TypeScript introduction to scalable javascript application
PPTX
Introducing type script
PPT
Learning typescript
PPT
TypeScript.ppt LPU Notes Lecture PPT for 2024
PPTX
Type script
PPTX
Typescript in 30mins
TypeScript: Basic Features and Compilation Guide
Type script - advanced usage and practices
Getting started with typescript
TypeScript: coding JavaScript without the pain
The advantage of developing with TypeScript
AngularConf2015
Getting started with typescript and angular 2
Type script
An Introduction to TypeScript
Type script
Typescript language extension of java script
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
TypeScript Introduction
TypeScript . the JavaScript developer best friend!
TypeScript introduction to scalable javascript application
Introducing type script
Learning typescript
TypeScript.ppt LPU Notes Lecture PPT for 2024
Type script
Typescript in 30mins
Ad

More from Yakov Fain (16)

PDF
Web sockets in Angular
PDF
Reactive Streams and RxJava2
PDF
Angular 4 for Java Developers
PDF
Reactive programming in Angular 2
PDF
Reactive Thinking in Java with RxJava2
PDF
Angular2 Development for Java developers
PDF
Reactive Thinking in Java
PDF
Overview of the AngularJS framework
PDF
Dart for Java Developers
PDF
Integrating consumers IoT devices into Business Workflow
PDF
Seven Versions of One Web Application
PDF
Running a Virtual Company
PDF
Princeton jug git_github
PDF
Speed up your Web applications with HTML5 WebSockets
PDF
Surviving as a Professional Software Developer
PDF
Becoming a professional software developer
Web sockets in Angular
Reactive Streams and RxJava2
Angular 4 for Java Developers
Reactive programming in Angular 2
Reactive Thinking in Java with RxJava2
Angular2 Development for Java developers
Reactive Thinking in Java
Overview of the AngularJS framework
Dart for Java Developers
Integrating consumers IoT devices into Business Workflow
Seven Versions of One Web Application
Running a Virtual Company
Princeton jug git_github
Speed up your Web applications with HTML5 WebSockets
Surviving as a Professional Software Developer
Becoming a professional software developer

Recently uploaded (20)

PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Nekopoi APK 2025 free lastest update
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
L1 - Introduction to python Backend.pptx
PPTX
Transform Your Business with a Software ERP System
PPT
Introduction Database Management System for Course Database
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
Online Work Permit System for Fast Permit Processing
PDF
top salesforce developer skills in 2025.pdf
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
ai tools demonstartion for schools and inter college
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PPTX
history of c programming in notes for students .pptx
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Odoo POS Development Services by CandidRoot Solutions
Nekopoi APK 2025 free lastest update
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
How Creative Agencies Leverage Project Management Software.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
L1 - Introduction to python Backend.pptx
Transform Your Business with a Software ERP System
Introduction Database Management System for Course Database
Design an Analysis of Algorithms II-SECS-1021-03
Online Work Permit System for Fast Permit Processing
top salesforce developer skills in 2025.pdf
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
ai tools demonstartion for schools and inter college
Upgrade and Innovation Strategies for SAP ERP Customers
Design an Analysis of Algorithms I-SECS-1021-03
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Internet Downloader Manager (IDM) Crack 6.42 Build 41
history of c programming in notes for students .pptx
ManageIQ - Sprint 268 Review - Slide Deck

Type script for_java_dev_jul_2020