marklovers / kaplay

🦖 A JavaScript game library
https://kaplayjs.com
MIT License
230 stars 14 forks source link

getSprite seems to have an invalid return type #173

Closed mflerackers closed 1 week ago

mflerackers commented 1 week ago

The current function signature is

getSprite(name: string): Asset<SpriteData> | void

Which looks invalid, a function either returns something, or not, you can't have both. This causes problems when writing either of these

getSprite("bean").then()
getSprite("bean")?.then()

Since in the case of void nothing gets returned, so ? doesn't solve anything. The correct function signature would be

getSprite(name: string): Asset<SpriteData> | null
lajbel commented 1 week ago

It's true

lajbel commented 1 week ago

fixed 1f52c92