Skip to content

Commit 7e747d6

Browse files
committed
Add exhaustive web case (to match C++)
1 parent 4c45ea1 commit 7e747d6

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

package/src/skia/web/JsiSkColor.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { SkColor, Color as InputColor } from "../types";
1+
import type { Color as InputColor, SkColor } from "../types";
22

33
const alphaf = (c: number) => ((c >> 24) & 255) / 255;
44
const red = (c: number) => (c >> 16) & 255;
@@ -329,12 +329,17 @@ export const Color = (color: InputColor): SkColor => {
329329
rgba[2] / 255,
330330
rgba[3]
331331
);
332-
} else {
332+
} else if (typeof color === "number") {
333333
return Float32Array.of(
334334
red(color) / 255,
335335
green(color) / 255,
336336
blue(color) / 255,
337337
alphaf(color)
338338
);
339+
} else {
340+
// Exhaustive case (though not possible on the type level, could be possible at runtime)
341+
throw new Error(
342+
`Skia.Color expected number, Float32Array, number[], or string and got: ${color}`
343+
);
339344
}
340345
};

0 commit comments

Comments
 (0)