color.js
color.js copied to clipboard
[types] Fix type errors in codebase
There are currently 176 type errors coming from the codebase itself. These are definitely worth fixing (not necessarily before v0.6.0, but at some point), so I'd like some feedback as to the best way to fix certain kinds of type-specific errors (i.e. type errors that aren't actually indicative of a problem with the JS logic).
A relatively common one is TS2322: Type 'number[]' is not assignable to type '[number, number, number]'
. An example of code causing this can be seen here:
Since the return value of multiplyMatrices
is not specific enough, it causes the aforementioned error. There are a few ways I can think of fixing this.
The first would be to simply ignore the error:
// @ts-expect-error
return multiplyMatrices(env.M, env.XYZ);
The second would be to assert as the proper type ([number, number, number]
):
return /** @type {[number, number, number]} */ (multiplyMatrices(env.M, env.XYZ));
And the third would just be to assert as any
:
return /** @type {any} */ (multiplyMatrices(env.M, env.XYZ));
I find it annoying that the type assertions with JSDoc are so ugly, but I'm not sure whether it's worth completely ignoring type checks for a line instead with a @ts-expect-error
directive. Thoughts?