Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chroma-js] fix bug with Scale.colors. #23997

Merged
merged 1 commit into from
Mar 9, 2018

Conversation

NaridaL
Copy link
Contributor

@NaridaL NaridaL commented Mar 1, 2018

Please fill in this template.

  • Use a meaningful title for the pull request. Include the name of the package modified.
  • Test the change in your own code. (Compile and run.)
  • Follow the advice from the readme.
  • Avoid common mistakes.
  • Run npm run lint package-name (or tsc if no tslint.json is present).

If changing an existing definition:

  • Provide a URL to documentation or source code which provides context for the suggested changes:
> c = require('chroma-js')
> c.scale(['white', c('red')]).colors()
[ '#ffffff', '#ff0000' ]
> c.scale(['white', c('red')]).colors(3)
[ '#ffffff', '#ff8080', '#ff0000' ]
> c.scale(['white', c('red')]).colors(undefined)
[ '#ffffff', '#ff0000' ]
> c.scale(['white', c('red')]).colors(undefined, null)
[ Color { _rgb: [ 255, 255, 255, 1, _clipped: false ] },
  Color { _rgb: [ 255, 0, 0, 1, _clipped: false ] } ]
> c.scale(['white', c('red')]).colors(undefined, undefined)
[ Color { _rgb: [ 255, 255, 255, 1, _clipped: false ] },
  Color { _rgb: [ 255, 0, 0, 1, _clipped: false ] } ]
> c.scale(['white', c('red')]).colors(undefined, 'css')
[ 'rgb(255,255,255)', 'rgb(255,0,0)' ]

colors(2) and colors(2, undefined) lead to different results ><

  • Increase the version number in the header if appropriate. Not necessary.
  • If you are making substantial changes, consider adding a tslint.json containing { "extends": "dtslint/dt.json" }. N/A

// which is passed as undefined/null or not passed at all
// const scaleColors1: Color[] = chroma.scale(['black', 'white']).colors(12);
const scaleColors2: Color[] = chroma.scale(['black', 'white']).colors(12, null);
const scaleColors3: Color[] = chroma.scale(['black', 'white']).colors(12, undefined);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bug was that, as the format parameter was marked as optional for all overloads, TS would pick the first one when null or undefined was passed, resulting in string[] cannot be assigned to Color[]

@typescript-bot
Copy link
Contributor

typescript-bot commented Mar 1, 2018

@NaridaL Thank you for submitting this PR!

🔔 @invliD @mpacholec - please review this PR in the next few days. Be sure to explicitly select Approve or Request Changes in the GitHub UI so I know what's going on.

If no reviewer appears after a week, a DefinitelyTyped maintainer will review the PR instead.

@typescript-bot typescript-bot added the Unmerged The author did not merge the PR when it was ready. label Mar 6, 2018
@typescript-bot
Copy link
Contributor

After 5 days, no one has reviewed the PR 😞. A maintainer will be reviewing the PR in the next few days and will either merge it or request revisions. Thank you for your patience!

@armanio123 armanio123 merged commit 6c40d88 into DefinitelyTyped:master Mar 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Unmerged The author did not merge the PR when it was ready.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants