New: Customer Portal - Adopt TypeScript for static type checking
Context
The Customer Portal is where our users purchase and manage subscriptions or licenses.
The project is a separate Rails app; and will continue to be that for the foreseeable future to serve self-managed users.
The number of developers calling that codebase home has increased quite a lot the last few months so we have extra bandwidth to make things nicer.
New Pattern Proposal: Customer Portal - Adopt TypeScript for static type checking
Use TypeScript as a type-checker for JS for the Customer Portal
Advantages of new pattern
- The Customer Portal is a relatively small isolated project to test how TypeScript fairs within GitLab; we can get first-hand experience with some of the pros/cons listed here
- Types serve documentation purposes: see this adventure
- Catches typos
- Vue has excellent support
- Updating Vue props and JS objects is propagated to the codebase
- Clear feedback of API definitions
Disadvantages of new pattern
- Introduces yet another tool to learn
- Adds additional type-checking time
- Types need to be maintained (notably
gitlab-ui
type maintenance) - Customer Portal and gitlab-core are not sharing same tech-stack
- Context shifting when coding/reviewing between Customer Portal and gitlab-core
- gitlab-core developers and maintainers might not be comfortable contributing code/reviews to a TypeScript codebase
- Initial productivity loss
- Risk of future productivity loss
- Overconfidence might lead to neglected tests
- TypeScript could actually lower our review standards and encourage code that's complex because technically it's type safe.
What is the impact on our existing codebase?
All existing JavaScript files (23 files, 1107 LOC) will be converted to TypeScript. Beyond changing the file extension from .js to .ts, some files may need slight modifications (i.e. adding explicit type annotations) to satisfy the TypeScript compiler.
cloc report
~/workspace/customers-gitlab-com staging
❯ npx cloc app/ --include-ext=js
npx: installed 1 in 0.547s
249 text files.
249 unique files.
231 files ignored.
github.com/AlDanial/cloc v 1.82 T=0.04 s (586.4 files/s, 35033.9 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
JavaScript 23 196 71 1107
-------------------------------------------------------------------------------
SUM: 23 196 71 1107
-------------------------------------------------------------------------------
Notes
- A lot of this has been cannibalized from gitlab-org/gitlab#19973 (moved)
- Why not, Flow, Reason, Elm, OCaml, Haxe? Previous discussions and previous efforts have been in TypeScript, we want to piggy-back on previous work
Edited by Ragnar Hardarson