SlideShare uma empresa Scribd logo
1 de 48
Baixar para ler offline
JOBS:
SOFTWARE ENGINEER & AGILE
COACH@HYPERFAR INC
COMMUNITIES:
UGIDOTNET | SCALA MILANO
MEETUP | MARKETERS
SLIDE & CODE:
HTTPS://GITHUB.COM/RUCKA/
KLAB2019-3
1 OCTOBER 2012
WHAT
TYPESCRIPT
IS?
IS
TYPESCRIPT == WEB +
?
!
IS
TYPESCRIPT == WEB + C#
?
!
NON-GOAL 1
> Exactly mimic the design of existing languages. Instead,
use the behavior of JavaScript and the intentions of
program authors as a guide for what makes the most
sense in the language
1
https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
NON-GOAL 1
> Exactly mimic the design of existing languages. Instead,
use the behavior of JavaScript and the intentions of
program authors as a guide for what makes the most
sense in the language
1
https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
GOALS 1
> Align with current and future ECMAScript proposals.
> Use a consistent, fully erasable, structural type
system.
1
https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
GOALS 1
> Align with current and future ECMAScript proposals.
> Use a consistent, fully erasable, structural type
system.
1
https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
USE A CONSISTENT, FULLY ERASABLE, STRUCTURAL TYPE SYSTEM
USE A CONSISTENT, FULLY
ERASABLE, STRUCTURAL TYPE
SYSTEM
USE A CONSISTENT,
FULLY ERASABLE,
STRUCTURAL TYPE
SYSTEM
STRUCTURAL
TYPE SYSTEM
A K A
NOMINAL TYPING
class Foo {public string me;}
class Bar {public string me;}
Foo foo = new Foo(){me = "foo"};
Bar bar = foo; //<--
//Error:
//cannot implicit convert
//type 'Foo' to 'Bar'
System.Console.WriteLine("I am "+ bar.me);
STRUCTURAL TYPING
interface Foo { me: string }
interface Bar { me: string }
const foo: Foo = { me: 'foo' }
const bar: Bar = foo
console.log(`I am ${bar.me}`); //I am foo
TYPESCRIPT ==
WEB + C#
DEMOTYPESCRIPT: A GENTLE INTRODUCTION
LET'S PLAY
WITH TYPES
GOALS 1
> Statically identify constructs that are likely to be
errors.
1
https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
1. PARAMETRIC POLIMORPHISM2
interface Valid<A> { a: A }
interface Invalid<E> { errors: E[] }
function save<A>(data: Valid<A>): void {
alert(`${JSON.stringfy(data.a)} saved!`);
}
function showErrors<E>(data: Invalid<E>): void {
alert(`${JSON.stringfy(data.errors)} :(`);
}
2
https://en.wikipedia.org/wiki/Parametric_polymorphism
2. UNION TYPES
type Validated<E, A> = Valid<A> | Invalid<E>
type CustomerError =
| NameIsEmpty
| NameIsTooShort
| VatCodeIsEmpty
| VatCodeNotValid
| EmailIsEmpty
| EmailIsNotValid
| WebsiteUrlNotValid
| TermsNotAccepted
3.1 DISCRIMINATED (TAGGED) UNION
interface NameIsTooShort { kind: 'NameIsTooShort', name: string }
interface VatCodeNotValid { kind: 'VatCodeNotValid', vatcode: string }
interface EmailIsNotValid { kind: 'EmailIsNotValid', email: string }
interface WebsiteUrlNotValid { kind: 'WebsiteUrlNotValid', url: string }
type CustomerError = NameIsTooShort | VatCodeNotValid | EmailIsNotValid | WebsiteUrlNotValid
function errorMessage(e: CustomerError): string {
switch (e.kind) {
case 'NameIsTooShort':
return `Name must be at least 3 chars long, actual is ${e.name.length}`;
case 'EmailIsNotValid':
return `Email address '${e.email}' is not valid`;
case 'VatCodeNotValid':
return `VAT code '${e.vatcode}' is not valid`;
case 'WebsiteUrlNotValid':
return `Url '${e.url}' is not valid`;
}
}
3.2 DISCRIMINATED (TAGGED) UNION
function isValid<A>(arg: any): arg is Valid<A> {
return arg.a !== undefined;
}
// here validatedCustomer is Validated<E, Customer>
if (isValid(validatedCustomer)) {
// here validatedCustomer is Valid<Customer>
return save(validatedCustomer);
} else {
// here validatedCustomer is Invalid<E>
return showErrors(validatedCustomer);
}
4. ITERSECTION TYPES
type A = {a: number}
type B = {b: number}
type I = A & B
let x: I = {a: 1, b: 2}; // OK
x = {a: 1, c: "three"}; // Error:
// Object literal may only specify known properties,
// and 'c' does not exist in type 'I'.
DEMOFUN(CTIONAL) VALIDATION
USING FUNCTIONAL PROGRAMMING
YOU ARE STILL ALIVE
(MAYBE)
UNDER THE HOOD...
ALGEBRAIC DATA TYPE3
(AKA ADT)
3
https://en.wikipedia.org/wiki/Algebraicdatatype
FUNCTOR4
4
https://en.wikipedia.org/wiki/Functor
(A SORT OF)
MONAD5
5
https://en.wikipedia.org/wiki/Monad(functionalprogramming)
C# LINQ
❤
MONAD6
(LiftA*)
SelectMany == flatMap
var result =
from r in rows
from c in colums
select "[" + r.Index + ", " + c.Index + "]";
var result = rows.SelectMany(r =>
columns.SelectMany(c =>
"[" + r.Index + ", " + c.Index + "]"));
6
http://mikehadlow.blogspot.com/2011/01/monads-in-c-4-linq-loves-monads.html
(A SORT OF)
APPLICATIVE7
7
https://en.wikipedia.org/wiki/Applicative_functor
HOMEWORK(IF YOU WANT TO BE A BETTER TYPESCRIPT DEV)
[MANDATORY]
USE TYPESCRIPT >= 2.0
(CURRENT VERSION IS 3.4)
[MANDATORY]
USE A CUSTOM TS.CONFIG
[MANDATORY]
ENABLE ALL COMPILER CHECKS
{
"compilerOptions": {
"strict": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"noEmitOnError": true,
"noImplicitAny": true,
"noImplicitThis": true,
"forceConsistentCasingInFileNames": true,
"strictNullChecks": true,
"alwaysStrict": true,
}
}
[SUGGESTION]
USE PRETTIER8
8
https://prettier.io
PREFER MODULES OVER NAMESPACES
USE FP-TS
THE RIGHT TOOL
FOR
THE RIGHT JOB
QUESTIONS?
KLab 2019 Meetup - TypeScript come (forse) non lo hai mai visto
KLab 2019 Meetup - TypeScript come (forse) non lo hai mai visto

Mais conteúdo relacionado

Mais procurados (13)

Java script
Java scriptJava script
Java script
 
Building Applications Using Ajax
Building Applications Using AjaxBuilding Applications Using Ajax
Building Applications Using Ajax
 
Html Server Anchor Control CS
Html Server Anchor Control CSHtml Server Anchor Control CS
Html Server Anchor Control CS
 
JavaScript - Part-1
JavaScript - Part-1JavaScript - Part-1
JavaScript - Part-1
 
Chapter 07 php forms handling
Chapter 07   php forms handlingChapter 07   php forms handling
Chapter 07 php forms handling
 
Test2
Test2Test2
Test2
 
Ajax
AjaxAjax
Ajax
 
2310 b 06
2310 b 062310 b 06
2310 b 06
 
Java Script
Java ScriptJava Script
Java Script
 
HTML Introduction
HTML IntroductionHTML Introduction
HTML Introduction
 
Vb.Net Web Forms
Vb.Net  Web FormsVb.Net  Web Forms
Vb.Net Web Forms
 
JavaScript Introduction
JavaScript IntroductionJavaScript Introduction
JavaScript Introduction
 
Angular2 compiler
Angular2 compilerAngular2 compiler
Angular2 compiler
 

Semelhante a KLab 2019 Meetup - TypeScript come (forse) non lo hai mai visto

CICONF 2012 - Don't Make Me Read Your Mind
CICONF 2012 - Don't Make Me Read Your MindCICONF 2012 - Don't Make Me Read Your Mind
CICONF 2012 - Don't Make Me Read Your Mind
ciconf
 
Lect-5--JavaScript-Intro-12032024-105816am.pptx
Lect-5--JavaScript-Intro-12032024-105816am.pptxLect-5--JavaScript-Intro-12032024-105816am.pptx
Lect-5--JavaScript-Intro-12032024-105816am.pptx
zainm7032
 
Hello I a having an issue with the code written in this ass.pdf
Hello I a having an issue with the code written in this ass.pdfHello I a having an issue with the code written in this ass.pdf
Hello I a having an issue with the code written in this ass.pdf
absgroup9793
 

Semelhante a KLab 2019 Meetup - TypeScript come (forse) non lo hai mai visto (20)

Ask The Expert - Typescript: A stitch in time saves nine
Ask The Expert - Typescript: A stitch in time saves nineAsk The Expert - Typescript: A stitch in time saves nine
Ask The Expert - Typescript: A stitch in time saves nine
 
CICONF 2012 - Don't Make Me Read Your Mind
CICONF 2012 - Don't Make Me Read Your MindCICONF 2012 - Don't Make Me Read Your Mind
CICONF 2012 - Don't Make Me Read Your Mind
 
apidays LIVE New York - API Code First vs Design First by Phil Sturgeon
apidays LIVE New York - API Code First vs Design First by Phil Sturgeonapidays LIVE New York - API Code First vs Design First by Phil Sturgeon
apidays LIVE New York - API Code First vs Design First by Phil Sturgeon
 
Basic JavaScript Tutorial
Basic JavaScript TutorialBasic JavaScript Tutorial
Basic JavaScript Tutorial
 
Java scipt
Java sciptJava scipt
Java scipt
 
Javascript
JavascriptJavascript
Javascript
 
Lect-5--JavaScript-Intro-12032024-105816am.pptx
Lect-5--JavaScript-Intro-12032024-105816am.pptxLect-5--JavaScript-Intro-12032024-105816am.pptx
Lect-5--JavaScript-Intro-12032024-105816am.pptx
 
GraphQL - when REST API is to less - lessons learned
GraphQL - when REST API is to less - lessons learnedGraphQL - when REST API is to less - lessons learned
GraphQL - when REST API is to less - lessons learned
 
Web programming
Web programmingWeb programming
Web programming
 
Testing web APIs
Testing web APIsTesting web APIs
Testing web APIs
 
GraphQL with .NET Core
GraphQL with .NET CoreGraphQL with .NET Core
GraphQL with .NET Core
 
Hello I a having an issue with the code written in this ass.pdf
Hello I a having an issue with the code written in this ass.pdfHello I a having an issue with the code written in this ass.pdf
Hello I a having an issue with the code written in this ass.pdf
 
CHAPTER 3 JS (1).pptx
CHAPTER 3  JS (1).pptxCHAPTER 3  JS (1).pptx
CHAPTER 3 JS (1).pptx
 
API Technical Writing
API Technical WritingAPI Technical Writing
API Technical Writing
 
Ractive js
Ractive jsRactive js
Ractive js
 
An Introduction to TypeScript
An Introduction to TypeScriptAn Introduction to TypeScript
An Introduction to TypeScript
 
2javascript web programming with JAVA script
2javascript web programming with JAVA script2javascript web programming with JAVA script
2javascript web programming with JAVA script
 
JavaScript New Tutorial Class XI and XII.pptx
JavaScript New Tutorial Class XI and XII.pptxJavaScript New Tutorial Class XI and XII.pptx
JavaScript New Tutorial Class XI and XII.pptx
 
GraphQL - when REST API is to less - lessons learned
GraphQL - when REST API is to less - lessons learnedGraphQL - when REST API is to less - lessons learned
GraphQL - when REST API is to less - lessons learned
 
CSC PPT 12.pptx
CSC PPT 12.pptxCSC PPT 12.pptx
CSC PPT 12.pptx
 

Último

%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 

Último (20)

WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 

KLab 2019 Meetup - TypeScript come (forse) non lo hai mai visto