From 9760b4ae7901e8d934907d90c689871b7014d8c3 Mon Sep 17 00:00:00 2001 From: Adrian Leonhard Date: Thu, 1 Mar 2018 10:49:33 +0100 Subject: [PATCH] [chroma-js] fix bug with Scale.colors. --- types/chroma-js/chroma-js-tests.ts | 9 +++++++++ types/chroma-js/index.d.ts | 8 ++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/types/chroma-js/chroma-js-tests.ts b/types/chroma-js/chroma-js-tests.ts index 82cfb7274d..fdd1b5946b 100644 --- a/types/chroma-js/chroma-js-tests.ts +++ b/types/chroma-js/chroma-js-tests.ts @@ -1,3 +1,6 @@ +import { Color } from "chroma-js"; +import chroma = require("chroma-js"); + function test_chroma() { chroma('hotpink'); chroma('#ff3399'); @@ -187,3 +190,9 @@ function test_types() { const color: chroma.Color = chroma('orange'); const scale: chroma.Scale = chroma.scale('RdYlBu'); } + +// the following should actually, pass, but TS can't disambiguate between a parameter +// 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); diff --git a/types/chroma-js/index.d.ts b/types/chroma-js/index.d.ts index c18484dc1f..797752c8ad 100644 --- a/types/chroma-js/index.d.ts +++ b/types/chroma-js/index.d.ts @@ -303,10 +303,10 @@ declare namespace chroma { * You can call scale.colors(n) to quickly grab `c` equi-distant colors from a color scale. If called with no * arguments, scale.colors returns the original array of colors used to create the scale. */ - colors(c?: number, format?: 'hex' | 'name'): string[]; - colors(c?: number, format?: null | 'alpha' | 'darken' | 'brighten' | 'saturate' | 'desaturate'): Color[]; - colors(c?: number, format?: 'luminance' | 'temperature'): number[]; - colors(c?: number, format?: K): Array; + colors(c: number | undefined, format: undefined | null | 'alpha' | 'darken' | 'brighten' | 'saturate' | 'desaturate'): Color[]; + colors(c: number | undefined, format: 'luminance' | 'temperature'): number[]; + colors(c: number | undefined, format: K): Array; + colors(c: number | undefined, format?: 'hex' | 'name'): string[]; /** * If you want the scale function to return a distinct set of colors instead of a continuous gradient, you can