Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Typescript: é tipo javascript?
Search
Gilson Doi Junior
February 27, 2020
Programming
20
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Typescript: é tipo javascript?
Gilson Doi Junior
February 27, 2020
More Decks by Gilson Doi Junior
See All by Gilson Doi Junior
Diretrizes JS Londrina
doijunior
0
18
Canvas: manual de sobrevivência
doijunior
0
15
Other Decks in Programming
See All in Programming
Family mrubyの進捗
kishima
1
100
AIに既存システムを理解させる技術 ~レガシーを見捨てないハーネスエンジニアリング入門~
ochtum
0
210
【デモ】Kiroで体験する仕様駆動開発|設計からコーディングまでAIと進める開発フロー
cmkudo
0
600
AWS DevOps Agentで インシデント対応をAIに任せたい
honmarkhunt
6
2.5k
From 6 People Classroom Meetup to 100 People Regional Conference / FOSS4G Hiroshima 2026
furukawayasuto
0
120
MIZARU@SPAJAM2026 第二回予選
1901drama
0
110
XP祭りでしか伝わらないフリップネタ #xpjug
murabayashi
0
110
LLMは4年分のCompose移行を再現できるのか?実プロダクト279件のXMLで探る自動化の境界線
makun
0
440
市販E-Readerを乗っ取れ 〜Embedded Swiftで電子ペーパーガジェットを制御する〜
trickart
0
120
標準パッケージに uuid が追加された 背景から見る Go らしい意思決定 / go_127_uuid_decision
convto
2
2.5k
LL言語やWebフレームワークのPostgreSQL対応 〜DBの機能がユーザーに届くまで〜
kentaroutakeda
0
140
What We Talk About When We Talk About XP
m_seki
2
390
Featured
See All Featured
Raft: Consensus for Rubyists
vanstee
141
7.7k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
270
Six Lessons from altMBA
skipperchong
29
4.5k
The Spectacular Lies of Maps
axbom
PRO
1
980
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.5k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.4k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.1k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.2k
My Coaching Mixtape
mlcsv
0
310
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
45k
Transcript
GILSON DOI JUNIOR TYPESCRIPT: é tipo javascript?
None
Não é uma linguagem
Não substitui o ECMAscript
FLEXIBILIDADE VS ESCALABILIDADE
➔ Tipagem Básica ◆ variáveis ◆ parâmetros ➔ Inferência automática
➔ Interface ➔ Class
“Mas a curva de aprendizagem é maior”
let result = isAnyTest( args) if (result === true) {
whatToDoWhenTrue() } else { whatToDoWhenFalse() } O que faz isAnyTest? Será que ele garante retorno? Será que não é bom testar undefined e null
app.use(async (ctx, next) => { User.save(ctx.body.username, ctx.body.password) }) Será que
o todos as informações vieram corretas no body, params e query do request?
function equation( a, b, c ) { a = Number(a)
b = Number(b) c = Number(c) ... } Será que o todos as informações vieram corretas no body, params e query do request? let concatChars = 'b'+'a'+ +'a'+ 'a'
Basic Types 1. Boolean 2. Number 3. String 4. Array
5. Tuple 6. Enum 7. Any 8. Void 9. Null and Undefined 10. Never 11. Object
Qual o objetivo? Any
Enum, Tuples e Types enum Roles {Admin, User, Client} type
UserProfile = { type: Roles.Admin, department: string, project:string } | { type: Roles.User, project:string } | { type: Roles.Client, product:string }; function printProfile( user : UserProfile) { switch (user.type) { case Roles.Admin: return `department ${user.department} - project ${user.project}` case Roles.User: return `project ${user.project}` case Roles.Client: return `product ${user.product}` } } let x: [string, number] = ["hello", 10]
Interface vs. Class Interface: • abstrato • não instanciável •
mutável/implementável Classe: • concreto • construído • vem “pronto”
Interface vs. Class enum Roles {Admin, User, Client} export interface
UserInterface { login: string; password: string; profile?: Object; role: Roles; authenticate() : boolean } let interfacedUser : UserInterface; interfacedUser.login = "teste"; //erro interfacedUser.password = "senha"; //erro export class BaseUser { login: string; password: string; profile?: Object; role: Roles; constructor( login : string, password : string) : void { ... } authenticate() : boolean { if(UserDB.authenticate(this.login, this.password)) { return true; } else return false; } }
Interface vs. Class class AdminUser implements UserInterface{ constructor( login :
string, password : string ) { this.login = login; this.password = password; this.role = Roles.Admin; } authenticate() : boolean { if(this.login === "teste" && this.password === "senha") { return true; } else { return false; } } } class ClientUser extends BaseUser{ profile?: Object; role: Roles; constructor( login : string, password : string ) { super(login, password) this.role = Roles.Admin; } //não existe obrigação para sobrescrever o método }
Enum Tuple Type Interface