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

Fix Color constructor parameter types #252

Merged
merged 2 commits into from
Dec 2, 2022
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
7 changes: 4 additions & 3 deletions types/src/color.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ import {
export type Coords = [number, number, number];

export interface ColorObject {
space: ColorSpace;
spaceId?: string | ColorSpace | undefined;
space?: string | ColorSpace | undefined;
coords: Coords;
alpha?: number;
alpha?: number | undefined;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it need | undefined if it's marked optional?

}

export interface ColorConstructor {
Expand Down Expand Up @@ -80,7 +81,7 @@ declare namespace Color {

declare class Color {
constructor(color: ColorTypes);
constructor(space: string | ColorSpace, coords: Coords, alpha: number);
constructor(space: string | ColorSpace, coords: Coords, alpha?: number);

// These signatures should always be the same as the constructor
static get(color: ColorTypes): Color;
Expand Down
3 changes: 1 addition & 2 deletions types/test/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import Color from "colorjs.io/src/color";

// @ts-expect-error
new Color();
// @ts-expect-error
new Color("srgb", [1, 2, 3]);

new Color("red");
new Color(new Color("red"));
new Color("srgb", [1, 2, 3]);
new Color("srgb", [1, 2, 3], 1);

const color = new Color("red");
Expand Down