replit / kaboom

💥 JavaScript game library
https://kaboomjs.com
MIT License
2.66k stars 226 forks source link

KaboomOpt.background doesn't support string as type def suggested #789

Closed namiwang closed 10 months ago

namiwang commented 10 months ago

In kaboom.d.ts, the type for KaboomOpt.background is number[] | string

/**
 * Kaboom configurations.
 */
export interface KaboomOpt<T extends PluginList<any> = any> {
  ...

  /**
  * Background color. E.g. [ 0, 0, 255 ] for solid blue background, or [ 0, 0, 0, 0 ] for transparent background.
  */
  background?: number[] | string,
...

However, when passing an string (e.g. white) as the value, an error will be thrown

Cannot read properties of null (reading '1')
TypeError: Cannot read properties of null (reading '1')
    at Color.fromHex (http://localhost:3000/static/js/bundle.js:90943:30)
    at rgb (http://localhost:3000/static/js/bundle.js:91025:43)
    at http://localhost:3000/static/js/bundle.js:92977:28
    at default (http://localhost:3000/static/js/bundle.js:93006:7)
    at createKaboom (http://localhost:3000/static/js/bundle.js:1490:57)
    at http://localhost:3000/static/js/bundle.js:156:58

version: 3000.1.17

slmjkdbtl commented 10 months ago

string is meant for hex values, I'll update the doc to clarify