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

[types] Add missing overload for set #419

Merged
merged 1 commit into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions types/src/color.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { WHITES } from "./adapt.js";
import defaults from "./defaults.js";
import hooks from "./hooks.js";
import * as util from "./util.js";
import ColorSpace from "./space.js";
import ColorSpace, { Ref } from "./space.js";
import SpaceAccessors from "./space-coord-accessors.js";

import {
Expand Down Expand Up @@ -130,14 +130,18 @@ declare class Color extends SpaceAccessors implements PlainColorObject {
// Functions defined using Color.defineFunctions
get: ToColorPrototype<typeof get>;
getAll: ToColorPrototype<typeof getAll>;
set: ToColorPrototype<typeof set>;
setAll: ToColorPrototype<typeof setAll>;
to: ToColorPrototype<typeof to>;
equals: ToColorPrototype<typeof equals>;
inGamut: ToColorPrototype<typeof inGamut>;
toGamut: ToColorPrototype<typeof toGamut>;
distance: ToColorPrototype<typeof distance>;
toString: ToColorPrototype<typeof serialize>;

// Must be manually defined due to overloads
// These should always match the signature of the original function
set (prop: Ref, value: number | ((coord: number) => number)): Color;
set (props: Record<string, number | ((coord: number) => number)>): Color;
}

export default Color;
4 changes: 4 additions & 0 deletions types/src/set.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ export default function set (
prop: Ref,
value: number | ((coord: number) => number)
): Color;
export default function set (
color: ColorTypes,
props: Record<string, number | ((coord: number) => number)>
): Color;
6 changes: 6 additions & 0 deletions types/test/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ set("red");
set("red", "foo", 123); // $ExpectType Color
set(new Color("red"), ["srgb", "bar"], (_: number) => 123); // $ExpectType Color
set(new Color("red"), [sRGB, "bar"], (_: number) => 123); // $ExpectType Color

// $ExpectType Color
set("red", {
foo: 123,
bar: (_: number) => 123,
});