Since I started to work with TypeScript I’m thinking “it’s really cool thing, but why should I waste so much time on writing and maintenance interfaces?”.
Well, this is a greatness and weakness of typed languages. In order to write robust applications you need to defined everything around.
And then… customer changes its requirements. GOTO step 1.
- Learn their own stuff
- Define entities manually, before writing code
So why not to reuse them and get all advantages of complex data types?
ESLint is mostly used for code styling, but it might seem at first sight only.
For example such rules as no-param-reassign, no-shadow or no-unresolved not allowed you to make mistakes writing code. Exactly the same is related to types: they enforce and restrict you to write code without errors.
All these thoughts have led me to writing custom rule for ESLint, which basically does types checking. In several last projects we actively used Swagger to describe APIs, which involves writing definitions on JSON Schema.
JSON Schema is a good and well documented standard and since 2nd version it even supports inheritance. Every JS application manages JSON data and I actually wonder why JSON Schema is not still everywhere.
So what basically TypeLint does, it binds your already existing JSON schema models with special JSDoc notations and validate code that you write.
Configure your IDE according to using additional rules and voilà
In addition we can easily validate native types using existing JSDoc notation with curly braces.
Check out the project and I hope it helps you to avoid a lot of bugs in future allowing to write code as fast as your business requirements need.