As a developer, I've always been a strong advocate for using Eslint and Prettier for type safety in JavaScript, even over
TypeScript programming language. I know this might be a bit controversial, but hear me out.
Number 1
First of all, Eslint and Prettier offer a lot of flexibility and customization options when it comes to enforcing coding standards and style. This not only improves code readability and consistency but also helps catch potential errors and bugs before they become a problem. With Typescript, while it offers type safety, it can be more rigid and may limit the ability to customize and enforce coding standards in the same way.
Number 2
Secondly, Eslint and Prettier are very easy to integrate into any JavaScript project, regardless of the framework or libraries being used. This can save a lot of time and effort, especially when working on multiple projects with different setups. With Typescript, there can be a steeper learning curve and more effort required to integrate it properly into a project.
Number 3
Finally, Eslint and Prettier have a large and active community, constantly updating and improving the tools with new features and fixes. This ensures that the tools remain up to date with the latest best practices and can adapt to changing development trends. While Typescript also has a large community, it may not be as active in updating and improving the language as frequently.
Of course, this is just my personal preference and I understand that different developers have different opinions and experiences. However, I believe that Eslint and Prettier provide a great solution for type safety in JavaScript and should be considered as a viable option, even over Typescript.
What are your thoughts on this? Do you prefer Eslint and Prettier or Typescript for type safety in JavaScript? Let's start a conversation in the comments!
Top comments (4)
Both eslint and prettier are indispensable tools, but I’m having a hard time seeing how either of them would be able to offer anything close to the level of type-safety that you get from typescript.
I’d be really interested to see some examples of the rules and configurations you’re using to to get a layer of type-safety from lint/prettier, to get my head around how far they can be leveraged for this.
I completely understand your point of view and agree that TypeScript provides a stronger level of type-safety than ESLint and Prettier. However, my argument is that for small projects, especially those that do not require the full features of TypeScript, ESLint and Prettier can provide enough type-safety and at the same time save time and effort.
To clarify, ESLint can catch a lot of common mistakes during development, such as undeclared variables, misspelled variable names, and other potential errors that can lead to runtime issues. And by using Prettier, code formatting is consistent and errors caused by formatting are reduced. This can be helpful in maintaining a clean and organized codebase.
Of course, TypeScript offers more advanced features for type-safety, but it also requires a learning curve and may not always be necessary for small projects. It ultimately comes down to the specific needs of each project and the resources available.
In terms of configurations and rules, there are various plugins and packages available for ESLint that can add type-safety checks to the code. For example, the "@typescript-eslint" plugin for ESLint allows developers to leverage TypeScript syntax for their ESLint configurations. This provides a level of type-checking that is not available with the basic ESLint configuration.
I hope you get what I mean 😉
I mean... Most typescript projects use prettier and eslint to enforce coding standards... They're not mutually exclusive at all. But like the other commenter I don't see how you can achieve type safety with eslint and prettier...
My bad, I failed to state the scope of which I published this post.
The post was created bearing in mind small projects.
I completely agree that using eslint and prettier for enforcing coding standards is a common practice in TypeScript projects.
However, my point in the hot take was that for small projects, using eslint and prettier with the right configuration can offer a certain level of type safety.
Of course, they can't completely replace TypeScript in terms of type safety, but they can help catch some errors and improve the overall quality of the code. It's all about finding the right balance and using the tools that work best for your specific project and team.