invert-color icon indicating copy to clipboard operation
invert-color copied to clipboard

TS2345

Open pjmattingly opened this issue 3 years ago • 1 comments

import invert from 'invert-color';

let _channels = [0, 0, 0];

let _new = invert.asRGB(_channels); //error

expected: This should work, as per:

https://github.com/onury/invert-color/blob/cd183934b67e4536e4e3f8a618067fb861fd63e2/lib/invert.d.ts

/**
 *  RGB list (array) type with red, green and blue components.
 */
export declare type RgbArray = [number, number, number];
...
export declare type Color = RGB | RgbArray | HexColor;

observed:

TS2345: Argument of type 'number[]' is not assignable to parameter of type 'Color'.
  Type 'number[]' is not assignable to type 'RgbArray'.
    Target requires 3 element(s) but source may have fewer.

pjmattingly avatar Nov 05 '21 23:11 pjmattingly

Use as const assertion:

const _channels = [0, 0, 0] as const;

let _new = invert.asRGB(_channels);

Jacob-Lockwood avatar Jul 01 '22 14:07 Jacob-Lockwood