New to TypeScript here and just wondering what the community views as best practice.
When I compile for production, I use the webpack loader. However, when I run my tests, I need to run tsc && ava
. This generates a .js
equivalent file in the same location as their .ts
counterparts. Should these by committed to the repo alongside the .ts
files? My first assumption is no because they should be re-compiled each time before a process e.g. starting your server or executing tests is run. However, I'd just like to get the community's opinion on this.
There's a caveat, if you are building a npm package with typescript and using git to host a private npm registry you will definitely want to commit the compiled . js files and their type definitions.
You shouldn't store credentials like usernames, passwords, API keys and API secrets. If someone else steals your credentials, they can do nasty things with it.
Your assumption is absolutely correct - build artefacts and outputs shouldn't be added to your repository. The main reason for this is that it's easy to end up in a situation where the source .ts
file has changed but the compiled .js
file differs because it's not been committed at the same time.
You also add complexity to your pull-requests/merge reviews, as there will be a large amount of generated code that isn't really part of the review but is in the changeset.
Finally, merging changes becomes a bit of a pain, because you need to recompile the .js
files for every merge you do.
If you only use .ts
files in your source directory, you can add /**/*.js
to your .gitignore
to prevent files from being added accidentally.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With