Skip to content

Commit 5b0f7b3

Browse files
committed
Update types for 'prepare' function
1 parent 293f164 commit 5b0f7b3

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

src/_prepare.d.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import parse from './parse.js';
2-
import type { Color, Mode } from './common';
2+
import type { Color, Find, Mode } from './common';
33

44
declare function prepare(color: undefined): undefined;
55
declare function prepare(color: string): ReturnType<typeof parse>;
6-
declare function prepare(color: Color): Color;
6+
declare function prepare<M extends Mode>(color: Find<Color, M>): Find<Color, M>;
77
declare function prepare<M extends Mode>(
8-
color: Omit<Color, 'mode'> & { mode?: M },
8+
color: Omit<Find<Color, M>, 'mode'>,
99
mode: M
10-
): Color;
10+
): Find<Color, M>;
1111
declare function prepare<M extends Mode>(
12-
color: Omit<Color, 'mode'> & { mode?: M },
13-
mode: undefined
12+
color: unknown,
13+
mode?: undefined
1414
): undefined;
1515

1616
export default prepare;

src/tests-for-types.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import { filterBrightness } from './filter';
1111
import { mapper, mapTransferLinear } from './map';
1212
import type { HslWithMode } from './hsl/types';
1313
import parseTransparent from './rgb/parseTransparent';
14+
import parse from './parse';
15+
import { Mode } from './common';
16+
import prepare from './_prepare';
1417

1518
const _a = random('rgb', {
1619
r: 1
@@ -75,3 +78,34 @@ const o: HslWithMode = filterBrightness(1)({
7578

7679
const p1: undefined = parseTransparent('asd');
7780
const p2: RgbWithMode = parseTransparent('transparent');
81+
82+
const pr: undefined = prepare(undefined);
83+
const pr2: Color | undefined = prepare('red');
84+
const pr3: RgbWithMode = prepare({
85+
mode: 'rgb',
86+
r: 0.2549019607843137,
87+
g: 0.4117647058823529,
88+
b: 0.8823529411764706
89+
});
90+
const pr4: RgbWithMode = prepare(
91+
{
92+
r: 0.2549019607843137,
93+
g: 0.4117647058823529,
94+
b: 0.8823529411764706
95+
},
96+
'rgb'
97+
);
98+
const pr5: undefined = prepare({
99+
r: 0.2549019607843137,
100+
g: 0.4117647058823529,
101+
b: 0.8823529411764706
102+
});
103+
104+
// declare function prepare<M extends Mode>(
105+
// color: Omit<Color, 'mode'> & { mode?: M },
106+
// mode: M
107+
// ): Color;
108+
// declare function prepare<M extends Mode>(
109+
// color: Omit<Color, 'mode'> & { mode?: M },
110+
// mode: undefined
111+
// ): undefined;

0 commit comments

Comments
 (0)