[color]: Show colors in types for developer QOL (#41265)

* add generic for developer QOL

* add to contributors

* fix types to be correct

* fix ColorParam type in test

* remove unnecessary function

* remove unnecessary generics

* use generic

* update ts version
This commit is contained in:
Adam Haglund
2020-01-03 00:20:45 +01:00
committed by Ryan Cavanaugh
parent e6e25944e6
commit a7b63a4e6a
2 changed files with 12 additions and 10 deletions

View File

@@ -1,7 +1,7 @@
import Color = require('color');
const color: Color = new Color("white");
const colorOther: Color = new Color("black");
const color: Color<"white"> = new Color("white");
const colorOther: Color<"black"> = new Color("black");
const colorRGB: Color = new Color({ r: 0, g: 0, b: 0 }, "rgb");
const colorInt: Color = new Color(0x000000);
const colorWithoutNew: Color = Color(0x000000);

View File

@@ -1,16 +1,18 @@
// Type definitions for color 3.0
// Project: https://github.com/qix-/color#readme
// Definitions by: Junyoung Clare Jang <https://github.com/Airlun>, James W. Lane <https://github.com/jameswlane>
// Definitions by: Junyoung Clare Jang <https://github.com/Airlun>
// James W. Lane <https://github.com/jameswlane>
// Adam Haglund <https://github.com/BeeeQueue>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
// TypeScript Version: 3.7
import convert = require('color-convert');
type ColorParam = Color | string | ArrayLike<number> | number | { [key: string]: any };
interface Color {
interface Color<T extends ColorParam = ColorParam> {
toString(): string;
toJSON(): Color;
toJSON(): Color<T>;
string(places?: number): string;
percentString(places?: number): string;
array(): number[];
@@ -65,9 +67,9 @@ interface Color {
b(): number;
b(val: number): Color;
keyword(): string;
keyword(val: string): Color;
keyword<V extends string>(val: V): Color<V>;
hex(): string;
hex(val: string): Color;
hex<V extends string>(val: V): Color<V>;
rgbNumber(): number;
luminosity(): number;
contrast(color2: Color): number;
@@ -102,8 +104,8 @@ interface Color {
}
interface ColorConstructor {
(obj?: ColorParam, model?: keyof (typeof convert)): Color;
new(obj?: ColorParam, model?: keyof (typeof convert)): Color;
<T extends ColorParam>(obj?: T, model?: keyof (typeof convert)): Color<T>;
new<T extends ColorParam>(obj?: T, model?: keyof (typeof convert)): Color<T>;
rgb(...val: number[]): Color;
rgb(color: ColorParam): Color;
hsl(...val: number[]): Color;