Type Safe "Everything"

Type Safe "Everything"

5c97d6b5611feeebc345c3e4742a05a8?s=128

andoshin11

March 04, 2020
Tweet

Transcript

  1. Type Safe “EVERYTHING” @andoshin11
 4. 3. 2020
 #tsc_api_study


  2. 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!
  3. • 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? ❤
  4. However...

  5. Not everyone speaks TypeScript (just yet...)

  6. 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...
  7. 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...
  8. Solution (we need)

  9. 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
  10. None
  11. Working Projects

  12. ① 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
  13. ① Typing Database Schema (db-recon)

  14. ① Typing Database Schema (db-recon)

  15. ① Typing Database Schema (db-recon)

  16. ① 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
  17. ② 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
  18. ② Typing API Request/Response (squelette)

  19. ② Typing API Request/Response (squelette)

  20. ② Typing API Request/Response (squelette)

  21. ② Typing API Request/Response (squelette)

  22. ② Typing API Request/Response (squelette) TODO: • Rewrite remaining ejs

    templates with TS Compiler API • Improve parser and AST format
  23. Latest addition

  24. Improving DX for express.js

  25. Remaining Pains...

  26. Remaining Pains... need manual mapping need to define types may

    contain typo
  27. Leads to fatal error in future...

  28. What if...

  29. All handlers are typed like a magic ‍♂

  30. None
  31. Introducing...

  32. typed-oax

  33. Generate express.d.ts from Open API

  34. Generate express.d.ts from Open API

  35. Generate express.d.ts from Open API

  36. DEMO

  37. typed-oax TODO: • Separate handler types by HTTP Method •

    Wrap with TS Plugin?