SlideShare a Scribd company logo
Introduction to
TypeScript
Sam Goldman
What is TypeScript
• typescriptlang.org
• Superset of JavaScript
• Optional static types
• Transpiles some js.next() features
• Targets ES3, ES5, and ES6 (new in TypeScript 1.4)
TypeScript Types
• Structural type system, as opposed to nominal
• Type inference
• Generics
Structural Types
interface Named {
name: string;
}
class Person {
name: string;
}
var p: Named;
// OK, because of structural typing
p = new Person();
Structural Types
interface Named {
name: string;
}
var x: Named;
// y's inferred type is { name: string; location: string; }
var y = { name: 'Alice', location: 'Seattle' };
x = y;
Structural Types
var x = (a: number) => 0;
var y = (b: number, s: string) => 0;
y = x; // OK
x = y; // Error
Type Inference
var x = 3;
// x: number
// Window.onmousedown: (ev: MouseEvent) => any
window.onmousedown = function(mouseEvent) {
console.log(mouseEvent.buton); //<- Error
};
Generics
interface Monoid<T> {
zero: T;
add: (x: T, y: T) => T;
}
var sum: Monoid<number> = {
zero: 0,
add: (x, y) => x + y
}
var product: Monoid<number> = {
zero: 1,
add: (x, y) => x * y
}
function reduce<T>(list: T[], monoid: Monoid<T>): T {
return list.reduce((acc, x) => monoid.add(acc, x), monoid.zero);
}
console.log(reduce([2, 4, 6], sum)); // 12
console.log(reduce([2, 4, 6], product)); // 48
Parametricity
interface ParametricityExamples {
identity: <T>(x: T) => T;
reverse: <T>(list: T[]) => T[];
constant: <A,B>(a:A) => (b:B) => A;
}
Definition Files
• Annotate non-TypeScript libraries with types
• Definitions are trusted, not checked
• Write your own or download someone else’s
Using Definition Files
• Cool kids provide .d.ts

github.com/Reactive-Extensions/RxJS/tree/master/ts

github.com/facebook/immutable-js/tree/master/type-definitions
• DefinitelyTyped

github.com/borisyankov/DefinitelyTyped

unofficial, uneven, but good for popular libraries
• TSD: TypeScript Definition Manager

definitelytyped.org/tsd

bundler/npm/bower for .d.ts files
Working with vim
• typescript-vim

https://github.com/leafgarland/typescript-vim

syntax highlighting, no indentation
• vim-js-indent

https://github.com/jason0x43/vim-js-indent
• typescript-tools

https://github.com/clausreinke/typescript-tools

code completion, type interrogation, quickfix

not yet compatible with 1.4 (issue #39)
Build
require('source-map-support').install();
var gulp = require("gulp");
var typescript = require("gulp-typescript");
var sourcemaps = require("gulp-sourcemaps");
var mocha = require("gulp-mocha");
Build
var typescriptProject = typescript.createProject({
noExternalResolve: true,
noImplicitAny: true,
target: "ES5",
module: "commonjs"
});
gulp.task("compile", function() {
return gulp
.src(["src/**/*.ts", "typings/**/*.d.ts"])
.pipe(sourcemaps.init())
.pipe(typescript(typescriptProject))
.pipe(sourcemaps.write("."))
.pipe(gulp.dest("build/src"))
});
Build
gulp.task("test", ["compile"], function() {
return gulp
.src("build/src/Spec/**/*.js")
.pipe(mocha({ reporter: "spec" }));
});
Beware any
var square = (n: number): number => n * n;
var json: string = '"not a number"';
var edge: number = JSON.parse(json);
var area: number = square(edge.width);
console.log("The area of the square is", area)
// The area of the square is NaN

More Related Content

What's hot (20)

PPT
Ajax and JavaScript Bootcamp
AndreCharland
 
PPTX
introduction to c #
Sireesh K
 
PDF
Scala fun part: Reflection(runtime)
vito jeng
 
PDF
Clojure Linters
Kent Ohashi
 
PDF
High Wizardry in the Land of Scala
djspiewak
 
PDF
C# Starter L03-Utilities
Mohammad Shaker
 
PPTX
Generics In and Out
Jaliya Udagedara
 
PPTX
06.1 .Net memory management
Victor Matyushevskyy
 
PPTX
JavaScript Basics - GameCraft Training
Radoslav Georgiev
 
PPTX
Дмитрий Контрерас «Back to the future: the evolution of the Java Type System»
Anna Shymchenko
 
PDF
Funcional Programming in Scala - Chapter 4
Chien Ku Chen
 
PDF
.NET Fest 2018. Дмитрий Иванов. Иммутабельные структуры данных в .NET: зачем ...
NETFest
 
PDF
Scala laboratory: Globus. iteration #2
Vasil Remeniuk
 
PDF
Clean Code (why not do it)
Diego Pacheco
 
PPTX
Session 08 - OOP with Java - continued
PawanMM
 
PPTX
Strong typing : adoption, adaptation and organisation
Damien Seguy
 
PDF
Crystal presentation in NY
Crystal Language
 
PPT
Scala uma poderosa linguagem para a jvm
Isaias Barroso
 
PPTX
Variables and Data Types
Infoviaan Technologies
 
PPTX
JavsScript OOP
LearningTech
 
Ajax and JavaScript Bootcamp
AndreCharland
 
introduction to c #
Sireesh K
 
Scala fun part: Reflection(runtime)
vito jeng
 
Clojure Linters
Kent Ohashi
 
High Wizardry in the Land of Scala
djspiewak
 
C# Starter L03-Utilities
Mohammad Shaker
 
Generics In and Out
Jaliya Udagedara
 
06.1 .Net memory management
Victor Matyushevskyy
 
JavaScript Basics - GameCraft Training
Radoslav Georgiev
 
Дмитрий Контрерас «Back to the future: the evolution of the Java Type System»
Anna Shymchenko
 
Funcional Programming in Scala - Chapter 4
Chien Ku Chen
 
.NET Fest 2018. Дмитрий Иванов. Иммутабельные структуры данных в .NET: зачем ...
NETFest
 
Scala laboratory: Globus. iteration #2
Vasil Remeniuk
 
Clean Code (why not do it)
Diego Pacheco
 
Session 08 - OOP with Java - continued
PawanMM
 
Strong typing : adoption, adaptation and organisation
Damien Seguy
 
Crystal presentation in NY
Crystal Language
 
Scala uma poderosa linguagem para a jvm
Isaias Barroso
 
Variables and Data Types
Infoviaan Technologies
 
JavsScript OOP
LearningTech
 

Viewers also liked (18)

PPTX
Type script
LearningTech
 
PDF
Building End to-End Web Apps Using TypeScript
Gil Fink
 
PPT
Learning typescript
Alexandre Marreiros
 
PDF
Typescript - MentorMate Academy
Dimitar Danailov
 
PPTX
Introduction about type script
Binh Quan Duc
 
PPTX
TypeScript Introduction
Travis van der Font
 
PDF
Introduction to Angular with TypeScript for .NET Developers
Laurent Duveau
 
PPTX
Typescript in 30mins
Udaya Kumar
 
PDF
TypeScript - An Introduction
NexThoughts Technologies
 
PPTX
Angular2 가기전 Type script소개
Dong Jun Kwon
 
PPTX
TypeScript Overview
Aniruddha Chakrabarti
 
PPTX
Typescript 101 introduction
Bob German
 
PPTX
Introduction to TypeScript
Bob German
 
PPTX
Getting started with typescript
C...L, NESPRESSO, WAFAASSURANCE, SOFRECOM ORANGE
 
PPTX
Deploy mbed IoT cloud
艾鍗科技
 
ODP
Getting started with typescript and angular 2
Knoldus Inc.
 
PDF
TypeScript: coding JavaScript without the pain
Sander Mak (@Sander_Mak)
 
PDF
Introduction to TypeScript by Winston Levi
Winston Levi
 
Type script
LearningTech
 
Building End to-End Web Apps Using TypeScript
Gil Fink
 
Learning typescript
Alexandre Marreiros
 
Typescript - MentorMate Academy
Dimitar Danailov
 
Introduction about type script
Binh Quan Duc
 
TypeScript Introduction
Travis van der Font
 
Introduction to Angular with TypeScript for .NET Developers
Laurent Duveau
 
Typescript in 30mins
Udaya Kumar
 
TypeScript - An Introduction
NexThoughts Technologies
 
Angular2 가기전 Type script소개
Dong Jun Kwon
 
TypeScript Overview
Aniruddha Chakrabarti
 
Typescript 101 introduction
Bob German
 
Introduction to TypeScript
Bob German
 
Getting started with typescript
C...L, NESPRESSO, WAFAASSURANCE, SOFRECOM ORANGE
 
Deploy mbed IoT cloud
艾鍗科技
 
Getting started with typescript and angular 2
Knoldus Inc.
 
TypeScript: coding JavaScript without the pain
Sander Mak (@Sander_Mak)
 
Introduction to TypeScript by Winston Levi
Winston Levi
 
Ad

Similar to Introduction to Type Script by Sam Goldman, SmartLogic (20)

PDF
Static types on javascript?! Type checking approaches to ensure healthy appli...
Arthur Puthin
 
PDF
A la découverte de TypeScript
Denis Voituron
 
PPTX
Exploring C# DSLs: LINQ, Fluent Interfaces and Expression Trees
rasmuskl
 
PDF
JavaScript 2016 for C# Developers
Rick Beerendonk
 
PDF
Demystifying Shapeless
Jared Roesch
 
PPT
Introduction to Csharp (C-Sharp) is a programming language developed by Micro...
NALESVPMEngg
 
PPT
Introduction-to-Csharp.ppt
mothertheressa
 
PPT
Introduction-to-Csharp programacion orientada a objetos
KilbertChusiHuamani
 
PPT
Introduction to-csharp
SDFG5
 
PPT
Introduction-to-Csharp.ppt
Almamoon
 
PDF
Introduction To Csharp
sarfarazali
 
PDF
Introduction to c#
singhadarsh
 
PDF
core java
dssreenath
 
PDF
JAZOON'13 - Paul Brauner - A backend developer meets the web: my Dart experience
jazoon13
 
PPT
C#
Joni
 
PPTX
C# 6 and 7 and Futures 20180607
Kevin Hazzard
 
PDF
More expressive types for spark with frameless
Miguel Pérez Pasalodos
 
PDF
OSCON Presentation: Developing High Performance Websites and Modern Apps with...
Doris Chen
 
PPT
Introduction to c#
OpenSource Technologies Pvt. Ltd.
 
PPT
Introduction to csharp
voegtu
 
Static types on javascript?! Type checking approaches to ensure healthy appli...
Arthur Puthin
 
A la découverte de TypeScript
Denis Voituron
 
Exploring C# DSLs: LINQ, Fluent Interfaces and Expression Trees
rasmuskl
 
JavaScript 2016 for C# Developers
Rick Beerendonk
 
Demystifying Shapeless
Jared Roesch
 
Introduction to Csharp (C-Sharp) is a programming language developed by Micro...
NALESVPMEngg
 
Introduction-to-Csharp.ppt
mothertheressa
 
Introduction-to-Csharp programacion orientada a objetos
KilbertChusiHuamani
 
Introduction to-csharp
SDFG5
 
Introduction-to-Csharp.ppt
Almamoon
 
Introduction To Csharp
sarfarazali
 
Introduction to c#
singhadarsh
 
core java
dssreenath
 
JAZOON'13 - Paul Brauner - A backend developer meets the web: my Dart experience
jazoon13
 
C#
Joni
 
C# 6 and 7 and Futures 20180607
Kevin Hazzard
 
More expressive types for spark with frameless
Miguel Pérez Pasalodos
 
OSCON Presentation: Developing High Performance Websites and Modern Apps with...
Doris Chen
 
Introduction to csharp
voegtu
 
Ad

More from SmartLogic (20)

PDF
Writing Game Servers with Elixir
SmartLogic
 
PDF
All Aboard The Stateful Train
SmartLogic
 
PDF
DC |> Elixir Meetup - Going off the Rails into Elixir - Dan Ivovich
SmartLogic
 
PDF
Monitoring Your Elixir Application with Prometheus
SmartLogic
 
PDF
Going Multi-Node
SmartLogic
 
PPTX
Kubernetes and docker
SmartLogic
 
PDF
Serializing Value Objects-Ara Hacopian
SmartLogic
 
PDF
Guide to food foraging by SmartLogic's Kei Ellerbrock
SmartLogic
 
PDF
How SmartLogic Uses Chef-Dan Ivovich
SmartLogic
 
PPTX
A Few Interesting Things in Apple's Swift Programming Language
SmartLogic
 
PDF
Effective ActiveRecord
SmartLogic
 
PDF
An Introduction to Reactive Cocoa
SmartLogic
 
PDF
iOS Development Methodology
SmartLogic
 
PPT
CSS Preprocessors to the Rescue!
SmartLogic
 
PDF
Deploying Rails Apps with Chef and Capistrano
SmartLogic
 
PDF
From Slacker to Hacker, Practical Tips for Learning to Code
SmartLogic
 
PDF
The Language of Abstraction in Software Development
SmartLogic
 
PDF
Android Testing: An Overview
SmartLogic
 
PPTX
Intro to DTCoreText: Moving Past UIWebView | iOS Development
SmartLogic
 
PDF
Logstash: Get to know your logs
SmartLogic
 
Writing Game Servers with Elixir
SmartLogic
 
All Aboard The Stateful Train
SmartLogic
 
DC |> Elixir Meetup - Going off the Rails into Elixir - Dan Ivovich
SmartLogic
 
Monitoring Your Elixir Application with Prometheus
SmartLogic
 
Going Multi-Node
SmartLogic
 
Kubernetes and docker
SmartLogic
 
Serializing Value Objects-Ara Hacopian
SmartLogic
 
Guide to food foraging by SmartLogic's Kei Ellerbrock
SmartLogic
 
How SmartLogic Uses Chef-Dan Ivovich
SmartLogic
 
A Few Interesting Things in Apple's Swift Programming Language
SmartLogic
 
Effective ActiveRecord
SmartLogic
 
An Introduction to Reactive Cocoa
SmartLogic
 
iOS Development Methodology
SmartLogic
 
CSS Preprocessors to the Rescue!
SmartLogic
 
Deploying Rails Apps with Chef and Capistrano
SmartLogic
 
From Slacker to Hacker, Practical Tips for Learning to Code
SmartLogic
 
The Language of Abstraction in Software Development
SmartLogic
 
Android Testing: An Overview
SmartLogic
 
Intro to DTCoreText: Moving Past UIWebView | iOS Development
SmartLogic
 
Logstash: Get to know your logs
SmartLogic
 

Recently uploaded (20)

PDF
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
PDF
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
PPTX
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PDF
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
PDF
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
PPTX
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PPTX
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
PDF
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
PPTX
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
PDF
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Human Resources Information System (HRIS)
Amity University, Patna
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 

Introduction to Type Script by Sam Goldman, SmartLogic

  • 2. What is TypeScript • typescriptlang.org • Superset of JavaScript • Optional static types • Transpiles some js.next() features • Targets ES3, ES5, and ES6 (new in TypeScript 1.4)
  • 3. TypeScript Types • Structural type system, as opposed to nominal • Type inference • Generics
  • 4. Structural Types interface Named { name: string; } class Person { name: string; } var p: Named; // OK, because of structural typing p = new Person();
  • 5. Structural Types interface Named { name: string; } var x: Named; // y's inferred type is { name: string; location: string; } var y = { name: 'Alice', location: 'Seattle' }; x = y;
  • 6. Structural Types var x = (a: number) => 0; var y = (b: number, s: string) => 0; y = x; // OK x = y; // Error
  • 7. Type Inference var x = 3; // x: number // Window.onmousedown: (ev: MouseEvent) => any window.onmousedown = function(mouseEvent) { console.log(mouseEvent.buton); //<- Error };
  • 8. Generics interface Monoid<T> { zero: T; add: (x: T, y: T) => T; } var sum: Monoid<number> = { zero: 0, add: (x, y) => x + y } var product: Monoid<number> = { zero: 1, add: (x, y) => x * y } function reduce<T>(list: T[], monoid: Monoid<T>): T { return list.reduce((acc, x) => monoid.add(acc, x), monoid.zero); } console.log(reduce([2, 4, 6], sum)); // 12 console.log(reduce([2, 4, 6], product)); // 48
  • 9. Parametricity interface ParametricityExamples { identity: <T>(x: T) => T; reverse: <T>(list: T[]) => T[]; constant: <A,B>(a:A) => (b:B) => A; }
  • 10. Definition Files • Annotate non-TypeScript libraries with types • Definitions are trusted, not checked • Write your own or download someone else’s
  • 11. Using Definition Files • Cool kids provide .d.ts
 github.com/Reactive-Extensions/RxJS/tree/master/ts
 github.com/facebook/immutable-js/tree/master/type-definitions • DefinitelyTyped
 github.com/borisyankov/DefinitelyTyped
 unofficial, uneven, but good for popular libraries • TSD: TypeScript Definition Manager
 definitelytyped.org/tsd
 bundler/npm/bower for .d.ts files
  • 12. Working with vim • typescript-vim
 https://github.com/leafgarland/typescript-vim
 syntax highlighting, no indentation • vim-js-indent
 https://github.com/jason0x43/vim-js-indent • typescript-tools
 https://github.com/clausreinke/typescript-tools
 code completion, type interrogation, quickfix
 not yet compatible with 1.4 (issue #39)
  • 13. Build require('source-map-support').install(); var gulp = require("gulp"); var typescript = require("gulp-typescript"); var sourcemaps = require("gulp-sourcemaps"); var mocha = require("gulp-mocha");
  • 14. Build var typescriptProject = typescript.createProject({ noExternalResolve: true, noImplicitAny: true, target: "ES5", module: "commonjs" }); gulp.task("compile", function() { return gulp .src(["src/**/*.ts", "typings/**/*.d.ts"]) .pipe(sourcemaps.init()) .pipe(typescript(typescriptProject)) .pipe(sourcemaps.write(".")) .pipe(gulp.dest("build/src")) });
  • 15. Build gulp.task("test", ["compile"], function() { return gulp .src("build/src/Spec/**/*.js") .pipe(mocha({ reporter: "spec" })); });
  • 16. Beware any var square = (n: number): number => n * n; var json: string = '"not a number"'; var edge: number = JSON.parse(json); var area: number = square(edge.width); console.log("The area of the square is", area) // The area of the square is NaN