Skip to content

Commit

Permalink
refactor: add explicit type casts (TS5.6.2)
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Oct 5, 2024
1 parent 11ae480 commit dcbdd60
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
9 changes: 6 additions & 3 deletions packages/blurhash/src/encode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,12 @@ export const encodeFromCanvas = (
) => {
return encode(
new Uint32Array(
canvas
.getContext("2d")!
.getImageData(0, 0, canvas.width, canvas.height).data.buffer
(<CanvasImageData>canvas.getContext("2d")).getImageData(
0,
0,
canvas.width,
canvas.height
).data.buffer
),
canvas.width,
canvas.height,
Expand Down
5 changes: 3 additions & 2 deletions packages/geom/src/scatter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { IShape } from "./api.js";
import type { IRandom } from "@thi.ng/random";
import { SYSTEM } from "@thi.ng/random/system";
import type { Vec } from "@thi.ng/vectors";
import { randMinMax } from "@thi.ng/vectors/rand-minmax";
import type { IShape } from "./api.js";
import { bounds } from "./bounds.js";
import { pointInside } from "./point-inside.js";

Expand All @@ -23,7 +24,7 @@ import { pointInside } from "./point-inside.js";
export const scatter = (
shape: IShape,
num: number,
rnd = SYSTEM,
rnd: IRandom = SYSTEM,
out: Vec[] = []
) => {
const b = bounds(shape);
Expand Down
3 changes: 2 additions & 1 deletion packages/k-means/src/kmeans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { IDistance } from "@thi.ng/distance";
import { argmin } from "@thi.ng/distance/argmin";
import { DIST_SQ } from "@thi.ng/distance/squared";
import { assert } from "@thi.ng/errors/assert";
import type { IRandom } from "@thi.ng/random";
import { SYSTEM } from "@thi.ng/random/system";
import { weightedRandom } from "@thi.ng/random/weighted-random";
import type { ReadonlyVec, Vec } from "@thi.ng/vectors";
Expand Down Expand Up @@ -84,7 +85,7 @@ export const initKmeanspp = <T extends ReadonlyVec>(
k: number,
samples: T[],
dist: IDistance<ReadonlyVec> = DIST_SQ,
rnd = SYSTEM
rnd: IRandom = SYSTEM
) => {
const num = samples.length;
assert(num > 0, `missing samples`);
Expand Down
3 changes: 2 additions & 1 deletion packages/pixel/src/canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export function canvasPixels(
ctx = c.ctx;
} else {
canvas = width;
ctx = canvas.getContext("2d")!;
// TODO remove cast again - temp workaround for TS5.6.2?
ctx = <any>canvas.getContext("2d");
}
if (parent && canvas instanceof HTMLCanvasElement)
parent.appendChild(canvas);
Expand Down
10 changes: 6 additions & 4 deletions packages/pixel/src/internal/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ export const __blitCanvas = (
| OffscreenCanvasRenderingContext2D,
opts: Partial<BlitCanvasOpts> = {}
) =>
(canvas instanceof HTMLCanvasElement || canvas instanceof OffscreenCanvas
? canvas.getContext("2d")!
: canvas
).putImageData(buf.toImageData(opts.data), opts.x || 0, opts.y || 0);
(<CanvasImageData>(
(canvas instanceof HTMLCanvasElement ||
canvas instanceof OffscreenCanvas
? canvas.getContext("2d")!
: canvas)
)).putImageData(buf.toImageData(opts.data), opts.x || 0, opts.y || 0);

0 comments on commit dcbdd60

Please sign in to comment.