Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
Type Safe "Everything"
andoshin11
March 04, 2020
Technology
0
160
Type Safe "Everything"
andoshin11
March 04, 2020
Tweet
Share
More Decks by andoshin11
See All by andoshin11
Private Cloudを支える最高のユーザーガイド運用技術
andoshin11
0
190
TS CompilerがVueを喋れても良いじゃないか
andoshin11
0
480
ain't giving up type-safe Express
andoshin11
2
310
Hack your Nuxt router!
andoshin11
0
880
GatewayパターンとSchema駆動開発
andoshin11
8
1.2k
Catch up Nuxt.js 2019.02
andoshin11
0
1.4k
The future of Nuxt.js with TypeScript
andoshin11
0
55
Clean Architecture with Vue
andoshin11
13
7.8k
vue-cli 3.0時代のNuxt.js
andoshin11
3
5.4k
Other Decks in Technology
See All in Technology
RDRA + JavaによるレジャーSaaSプロダクトの要件定義と実装のシームレスな接続
jjebejj
PRO
3
490
Scrum Fest Osaka 2022 フルリモート下でのチームビルディング
moritamasami
2
920
マネージャーからみたスクラムと自己管理化
shibe23
0
940
What's new in Vision
satotakeshi
0
130
ウォーターフォールとアジャイルと楽楽明細/Waterfall×Agile×Rakurakumeisai
whitefox_73
1
340
suppress-ts-errors を使って TypeScriptの型チェックを漸進的に強化する / Introducing-suppress-ts-errors
kawamataryo
2
110
1人目SETとして入社して2ヶ月の間におこなったこと
tarappo
3
400
Target SDK Versionを上げない Notification runtime permission対応
napplecomputer
0
110
History of the ML system in KARTE
kargo113
0
540
越境チャレンジの現在地 〜Epic大臣制度の今〜
yousak
0
700
さいきんのRaspberry Pi。 / osc22do-rpi
akkiesoft
4
4.4k
Custom AppをIP制限ありのままで審査に通す方法
yusuga
0
290
Featured
See All Featured
Teambox: Starting and Learning
jrom
123
7.7k
Building Applications with DynamoDB
mza
83
4.7k
Creatively Recalculating Your Daily Design Routine
revolveconf
207
10k
Practical Orchestrator
shlominoach
178
8.6k
No one is an island. Learnings from fostering a developers community.
thoeni
9
1.1k
How To Stay Up To Date on Web Technology
chriscoyier
780
250k
Keith and Marios Guide to Fast Websites
keithpitt
404
21k
How to name files
jennybc
40
60k
Art Directing for the Web. Five minutes with CSS Template Areas
malarkey
196
9.4k
Bootstrapping a Software Product
garrettdimon
296
110k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
224
49k
10 Git Anti Patterns You Should be Aware of
lemiorhan
638
52k
Transcript
Type Safe “EVERYTHING” @andoshin11 4. 3. 2020 #tsc_api_study
Who am I ? Shin Ando (a.k.a Andy) @andoshin11 -
Freelance Full-Stack Developer - TypeScript / Vue.js / React / Go / Ruby / Flutter / Terraform / etc… - ❤ Code Generation!
• Powerful editor completion • Easy to analyze code base
using AST • Type-level programming • Overall durability • Maintainable • Scalable • F**king AWESOME!! We all love TypeScript, eh? ❤
However...
Not everyone speaks TypeScript (just yet...)
Not everyone speaks TypeScript (just yet...) • Other programming languages
(Go, Ruby, Python, Java, etc...) • Query based languages (a.k.a Database) • Statically defined specs (YAML, CSV, Markdown, Excel) • etc...
Not everyone speaks TypeScript (just yet...) • Other programming languages
(Go, Ruby, Python, Java, etc...) • Query based languages (a.k.a Database) • Statically defined specs (YAML, CSV, Markdown, Excel) • etc...
Solution (we need)
Basic aproach Parser Transformer TS Compiler 1. Parse input and
tokenize into JSON 2. Transform tokens to TypeScript AST 3. Validate AST and emit useful code Outcome
None
Working Projects
① Typing Database Schema (db-recon) • db-recon ( https://github.com/andoshin11/db-recon )
• Generates type-safe db client for Node.js application • Supports MySQL and MSSQL currently
① Typing Database Schema (db-recon)
① Typing Database Schema (db-recon)
① Typing Database Schema (db-recon)
① Typing Database Schema (db-recon) TODO: • Create SQL-to-AST parser
• Get semantic diagnostics for raw SQL literal string ( ts-sql-plugin requires DSL ) • Rewrite ejs templates with TS Compiler API
② Typing API Request/Response (squelette) • squelette ( https://github.com/andoshin11/squelette )
• Generates type definitions for API request/response from Open API spec • Toolchain to build your own type-safe API client
② Typing API Request/Response (squelette)
② Typing API Request/Response (squelette)
② Typing API Request/Response (squelette)
② Typing API Request/Response (squelette)
② Typing API Request/Response (squelette) TODO: • Rewrite remaining ejs
templates with TS Compiler API • Improve parser and AST format
Latest addition
Improving DX for express.js
Remaining Pains...
Remaining Pains... need manual mapping need to define types may
contain typo
Leads to fatal error in future...
What if...
All handlers are typed like a magic ♂
None
Introducing...
typed-oax
Generate express.d.ts from Open API
Generate express.d.ts from Open API
Generate express.d.ts from Open API
DEMO
typed-oax TODO: • Separate handler types by HTTP Method •
Wrap with TS Plugin?