2 ms·
May I recommend adding a static type checker to your tooling. You can annotate function types with TypeScript using JSDoc comments[1], or Flow[2] and transpile
by runarberg 6y ago
May I recommend adding a static type checker to your tooling. You can annotate function types with TypeScript using JSDoc comments[1], or Flow[2] and transpile the annotations away with babel.Then you would run the type checker as you would run your linter as part of your CI.
1. https://www.typescriptlang.org/docs/handbook/intro-to-js-ts.html https://www.typescriptlang.org/docs/handbook/intro-to-js-ts....
2. https://flow.org/ https://flow.org/
- bachmeier 6y ago> May I recommend adding a static type checker to your tooling. I fully understand that the JS community has a thing for dependencies, and views Amazon as its representative use case, but I was hoping to add a few small Javascript functions to a static html page. JS loses its appeal quickly when you start adding things like that - if I can't open an html file in a text editor and add the functions I need, I might as well use a different language.
- madeofpalk 6y agoI'm not really sure what Amazon has to do with this, but the problem you described - "I changed the API and forgot to update a part of the application" - is exactly what type checking is for. This is not a "JS community has a thing for..." bit, this applies to any programming language.
- jakelazaroff 6y agoI'm not sure what other language you could use to add client-side functionality to a static webpage? But anyway, if you want to avoid a compilation step, the link GP mentioned shows how TypeScript can check JS files annotated with normal comments. You can run it through the a compiler to remove the annotations if you want, but it's absolutely not required.
- AgentME 6y agoAs someone who has used both Flow and Typescript for years, I'd recommend Typescript over Flow. You can use Babel to compile Typescript code just like you can with Flow and have Typescript do its type-checking in CI. Typescript has better editor integration, more type-definitions for libraries, and breaks compatibility much less often than Flow.