color-js / color.js

Color conversion & manipulation library by the editors of the CSS Color specifications
https://colorjs.io
MIT License
1.89k stars 82 forks source link

Color.js typing for Coords is number even though functions may return null #527

Closed KeyboardDanni closed 4 months ago

KeyboardDanni commented 4 months ago

Related to https://github.com/color-js/color.js/issues/409

The typing for Coords seems to be out of date:

https://github.com/color-js/color.js/blob/551021a05579c8556ae454e46356adaccf9a8d4f/types/src/color.d.ts#L27

Since NaN has been replaced with null, there is no longer a guarantee that the values coming back will be number. Was getting a runtime error with the latest git when my color sliders tried to call toString() on the color values, but one of them ended up being null. I was confused at first because TypeScript didn't complain about the typing.