The fine art of crafting a TypeScript definition file
- Provide error checking
- Faster exploration
- Counterpart to documentation
- Developers trust compile errors
- Bad type data is a timesink
- Good definition files increase confidence
- Complete
- Correct
- Concise
Write a FINER definition:
- Familiarize yourself with the library
- Identify its structure
- Name its important types
- Enumerate its properties
- Review and Refactor
- Read the documentation
- Understand its common patterns
- Skim the API reference
- Read the samples
- Is this a global library? UMD? Plugin?
- Get the appropriate template
- Review structure-specific guidance
- Identify reusable type constructs
- Try to have few anonymous types
- Use inheritance where it makes sense
- Use the same names as the documentatoin
- Find API reference
- Define each function / property
- Add new types as you go, if needed
- Check for common errors
- Check for duplication
- Refactor types if needed
- Bad overload ordering
- Bad overload structuring
- String, Number, Boolean
- Unused generic parameters