all aboard the type train all aboard the type train
play

All Aboard the Type Train All Aboard the Type Train Kadi Kraman - PowerPoint PPT Presentation

All Aboard the Type Train All Aboard the Type Train Kadi Kraman Kadi Kraman @kadikraman Formidable Why this talk? Why this talk? Why add types to JavaScript? Why add types to JavaScript? Should you use Flow or TypeScript? Should you use


  1. All Aboard the Type Train All Aboard the Type Train Kadi Kraman Kadi Kraman @kadikraman Formidable

  2. Why this talk? Why this talk?

  3. Why add types to JavaScript? Why add types to JavaScript? Should you use Flow or TypeScript? Should you use Flow or TypeScript? ... or something else entirely!

  4. All programming languages All programming languages have a type system have a type system The difference is The difference is when when the type- the type- checking is done checking is done

  5. Strong vs Weak Strong vs Weak Languages are often colloquially referred to as strongly typed or weakly typed . There is no universally accepted definition of what these terms mean. � ♀ � ♀

  6. Static vs Dynamic Static vs Dynamic Static (e.g. Go, C#, Haskell) Static (e.g. Go, C#, Haskell) Types are checked before run-time Dynamic (Python, Lua, Objective C) Dynamic (Python, Lua, Objective C) Types are checked at run-time, during execution JavaScript is a Dynamically Typed language

  7. Static typing Static typing (not JavaScript) Pros Pros Cons Cons More errors found earlier in Verbose type declarations development Complex error messages Fewer errors at run-time and shipped code Excessive boilerplate No need to write tests for "type-correctness"

  8. Dynamic typing Dynamic typing (e.g. JavaScript) Pros Pros Cons Cons Reduces clutter and More errors detected during repetition in code run time and in shipped code Implicit polymorphism (the Need to write tests for type ability to write a single correctness function that handles many data-types)

  9. DISCLAIMER! DISCLAIMER! Additional type-checking Additional type-checking will not make code bug-free will not make code bug-free It is not a replacement for testing your code It only helps reduce type errors

  10. How to make JavaScript How to make JavaScript more type-safe? more type-safe? 1. 1. Static code analysis 2. 2. Statically typed language that compiles to JavaScript

  11. 1. 1. Static code analysis Facebook 2014 Flow - static type checker Flow - static type checker Infers type information from existing code You can choose to enforce types (Atom, with Flow plugin)

  12. 2. 2. Statically typed language that compiles to JavaScript TypeScript - a superset of TypeScript - a superset of JavaScript JavaScript Microsoft 2012 Infers type information from existing code You can choose to enforce types (VSCode, with TypeScript plugin)

  13. Adding to an Adding to an existing codebase existing codebase Flow Flow TypeScript TypeScript "Opt in" by adding a TS is a superset of JS flow declaration at the (so any valid JS file is top of the file also a valid TS file) But you do have to change the file extension to .ts

  14. Configuration Configuration Flow Flow TypeScript TypeScript

  15. Performance Performance Flow Flow TypeScript TypeScript Usually fast, but Slow to recompile on notoriously unstable large projects �

  16. Community Community Flow Flow (by Facebook, 2014) TypeScript TypeScript (by Microsoft, 2012)

  17. Typing Node Modules Typing Node Modules Flow Flow TypeScript TypeScript

  18. So why are a lot of projects So why are a lot of projects moving to TypeScript? moving to TypeScript? Larger community Faster release cycle More reliable The features that made flow "better" have been implemented in TypeScript

  19. What you should know before jumping What you should know before jumping on the TypeScript "Type Train" on the TypeScript "Type Train" For best results, use VSCode tslint (the TypeSctipt linter) will be deprecated in 2019 So use typescript-eslint Be prepared for a lot of Object Oriented influence TypeScript is a compiled language , not a static type-checker - if you have type errors in your code, it will not compile

  20. "Why not just use a proper statically typed "Why not just use a proper statically typed language?" language?" Elm (2012 by Evan Czaplicki) Compiled, statically typed, type declarations are optional, purely functional. ReasonML (2016 by Jordan Walke at Facebook) Transpiles to OCaml which compiles to JS, statically typed

  21. Thank You � Thank You � All Aboard the Type Train All Aboard the Type Train by Kadi Kraman (@kadikraman)

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend