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
Type Safe "Everything"
Search
andoshin11
March 04, 2020
Technology
0
220
Type Safe "Everything"
andoshin11
March 04, 2020
Tweet
Share
More Decks by andoshin11
See All by andoshin11
Envoy External AuthZとgRPC Extensionを利用した「頑張らない」Microservices認証認可基盤
andoshin11
0
290
カーナベル株式会社2024年2月 エンジニアイベント資料
andoshin11
0
120
Private Cloudを支える最高のユーザーガイド運用技術
andoshin11
0
270
TS CompilerがVueを喋れても良いじゃないか
andoshin11
0
690
ain't giving up type-safe Express
andoshin11
2
400
Hack your Nuxt router!
andoshin11
0
1.2k
GatewayパターンとSchema駆動開発
andoshin11
8
1.3k
Catch up Nuxt.js 2019.02
andoshin11
0
1.9k
The future of Nuxt.js with TypeScript
andoshin11
0
80
Other Decks in Technology
See All in Technology
Automated Promptingを目指すその前に / Before we can aim for Automated Prompting
rkaga
0
110
GitHub Universe: Evaluating RAG apps in GitHub Actions
pamelafox
0
170
ガチ勢によるPipeCD運用大全〜滑らかなCI/CDを添えて〜 / ai-pipecd-encyclopedia
cyberagentdevelopers
PRO
3
200
2024-10-30-reInventStandby_StudyGroup_Intro
shinichirokawano
1
630
30万人が利用するチャットをFirebase Realtime DatabaseからActionCableへ移行する方法
ryosk7
5
350
Shift-from-React-to-Vue
calm1205
3
1.3k
プロダクトエンジニアが活躍する環境を作りたくて 事業責任者になった話 ~プロダクトエンジニアの行き着く先~
gimupop
1
480
スプリントゴールにチームの状態も設定する背景とその効果 / Team state in sprint goals why and impact
kakehashi
2
100
コンテンツを支える 若手ゲームクリエイターの アートディレクションの事例紹介 / cagamefi-game
cyberagentdevelopers
PRO
1
130
カメラを用いた店内計測におけるオプトインの仕組みの実現 / ai-optin-camera
cyberagentdevelopers
PRO
1
120
現地でMeet Upをやる場合の注意点〜反省点を添えて〜
shotashiratori
0
520
オニオンアーキテクチャで実現した 本質課題を解決する インフラ移行の実例
hryushm
14
3k
Featured
See All Featured
A Philosophy of Restraint
colly
203
16k
Into the Great Unknown - MozCon
thekraken
31
1.5k
Making the Leap to Tech Lead
cromwellryan
132
8.9k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Code Review Best Practice
trishagee
64
17k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
Adopting Sorbet at Scale
ufuk
73
9k
Art, The Web, and Tiny UX
lynnandtonic
296
20k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Building Adaptive Systems
keathley
38
2.2k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
355
29k
The Invisible Side of Design
smashingmag
297
50k
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?