Skip to content

Commit dcbdd60

Browse files
refactor: add explicit type casts (TS5.6.2)
1 parent 11ae480 commit dcbdd60

File tree

5 files changed

+19
-11
lines changed

5 files changed

+19
-11
lines changed

packages/blurhash/src/encode.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,12 @@ export const encodeFromCanvas = (
9595
) => {
9696
return encode(
9797
new Uint32Array(
98-
canvas
99-
.getContext("2d")!
100-
.getImageData(0, 0, canvas.width, canvas.height).data.buffer
98+
(<CanvasImageData>canvas.getContext("2d")).getImageData(
99+
0,
100+
0,
101+
canvas.width,
102+
canvas.height
103+
).data.buffer
101104
),
102105
canvas.width,
103106
canvas.height,

packages/geom/src/scatter.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import type { IShape } from "./api.js";
1+
import type { IRandom } from "@thi.ng/random";
22
import { SYSTEM } from "@thi.ng/random/system";
33
import type { Vec } from "@thi.ng/vectors";
44
import { randMinMax } from "@thi.ng/vectors/rand-minmax";
5+
import type { IShape } from "./api.js";
56
import { bounds } from "./bounds.js";
67
import { pointInside } from "./point-inside.js";
78

@@ -23,7 +24,7 @@ import { pointInside } from "./point-inside.js";
2324
export const scatter = (
2425
shape: IShape,
2526
num: number,
26-
rnd = SYSTEM,
27+
rnd: IRandom = SYSTEM,
2728
out: Vec[] = []
2829
) => {
2930
const b = bounds(shape);

packages/k-means/src/kmeans.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { IDistance } from "@thi.ng/distance";
22
import { argmin } from "@thi.ng/distance/argmin";
33
import { DIST_SQ } from "@thi.ng/distance/squared";
44
import { assert } from "@thi.ng/errors/assert";
5+
import type { IRandom } from "@thi.ng/random";
56
import { SYSTEM } from "@thi.ng/random/system";
67
import { weightedRandom } from "@thi.ng/random/weighted-random";
78
import type { ReadonlyVec, Vec } from "@thi.ng/vectors";
@@ -84,7 +85,7 @@ export const initKmeanspp = <T extends ReadonlyVec>(
8485
k: number,
8586
samples: T[],
8687
dist: IDistance<ReadonlyVec> = DIST_SQ,
87-
rnd = SYSTEM
88+
rnd: IRandom = SYSTEM
8889
) => {
8990
const num = samples.length;
9091
assert(num > 0, `missing samples`);

packages/pixel/src/canvas.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ export function canvasPixels(
3131
ctx = c.ctx;
3232
} else {
3333
canvas = width;
34-
ctx = canvas.getContext("2d")!;
34+
// TODO remove cast again - temp workaround for TS5.6.2?
35+
ctx = <any>canvas.getContext("2d");
3536
}
3637
if (parent && canvas instanceof HTMLCanvasElement)
3738
parent.appendChild(canvas);

packages/pixel/src/internal/utils.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ export const __blitCanvas = (
152152
| OffscreenCanvasRenderingContext2D,
153153
opts: Partial<BlitCanvasOpts> = {}
154154
) =>
155-
(canvas instanceof HTMLCanvasElement || canvas instanceof OffscreenCanvas
156-
? canvas.getContext("2d")!
157-
: canvas
158-
).putImageData(buf.toImageData(opts.data), opts.x || 0, opts.y || 0);
155+
(<CanvasImageData>(
156+
(canvas instanceof HTMLCanvasElement ||
157+
canvas instanceof OffscreenCanvas
158+
? canvas.getContext("2d")!
159+
: canvas)
160+
)).putImageData(buf.toImageData(opts.data), opts.x || 0, opts.y || 0);

0 commit comments

Comments
 (0)