3 ms·
JavaScript dev here. Type related Mistakes are common but A LOT of tests keep me safe. I avoid using the Object constructor for data that is passed around a lot
by tobyhinloopen 9y ago
JavaScript dev here. Type related Mistakes are common but A LOT of tests keep me safe. I avoid using the Object constructor for data that is passed around a lot and use functions as constructors to create common data structures to ensure their structure and properties are consistent. Simple example:
function User (name, email) { this.name = name; this.email = email; }
This simple solution prevents lots of common typing mistakes where object properties are inconsistent.
Sometimes I include some specific development-only type-checks on the params as well
We cant use Typescript, I would love to use it though