ondras / rot.js

ROguelike Toolkit in JavaScript. Cool dungeon-related stuff, interactive manual, documentation, tests!
https://ondras.github.io/rot.js/hp/
BSD 3-Clause "New" or "Revised" License
2.33k stars 254 forks source link

Types for map generation incorrectly require callback #143

Closed bbugh closed 5 years ago

bbugh commented 5 years ago

There is an issue with map generator create methods requiring a callback even if the usage doesn't require it.

Current Behavior

Attempting to call the create method of the Cellular map generate (and others, it looks like) will cause an error.

const generator = new Cellular(width, height)
generator.create() // Expected 1 arguments, but got 0. An argument for 'callback' was not provided.

// have to put in an empty callback to make it work
generator.create(() => {}) // not ideal, and tslint complains

I found this on the Cellular map but it appears to be a problem in other cases. I don't know the full extent or I would submit a PR for it. I believe it's an easy fix, though. Here is the relevant code:

https://github.com/ondras/rot.js/blob/754d7967aec6af5cefdce70fab8e70de05df41d3/src/map/cellular.ts#L65

Expected Behavior

It appears that according to the docs and the code (and my own experiments), this parameter is not required.

I believe that this method (and other CreateCallback) should be defined as

create(callback?: CreateCallback) {  // add the ? to make it optional 

The code already correctly checks the presence of the value, so I don't think any other changes are required to fix this.

ondras commented 5 years ago

Hi @bbugh,

thanks for the bugreport. I just pushed a new version where these callbacks have correct optional signatures.

bbugh commented 5 years ago

Wow, quick turnaround, thanks! It's working great. Much appreciated.