Skip to content

Commit

Permalink
Upgrade to TypeScript 5.7 (#14167)
Browse files Browse the repository at this point in the history
* Upgrade to TypeScript 5.7

* Update ndarray() to use ArrayBufferLike
  • Loading branch information
mattpap authored Nov 25, 2024
1 parent eb6eb51 commit c829640
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 20 deletions.
2 changes: 1 addition & 1 deletion bokehjs/make/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"semver": "^7.6.2",
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
"typescript": "~5.6.2",
"typescript": "~5.7.2",
"typescript-eslint": "^7.16.0",
"which": "^3.0.1",
"yargs": "^17.7.2"
Expand Down
18 changes: 9 additions & 9 deletions bokehjs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bokehjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"regl": "^2.1.0",
"sprintf-js": "^1.1.3",
"timezone": "^1.0.23",
"tslib": "^2.7.0",
"tslib": "^2.8.1",
"underscore.template": "^0.1.7"
}
}
2 changes: 1 addition & 1 deletion bokehjs/src/compiler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"css": "^3.0.0",
"less": "^4.2.0",
"terser": "^5.31.2",
"typescript": "~5.6.2",
"typescript": "~5.7.2",
"yargs": "^17.7.2"
}
}
21 changes: 13 additions & 8 deletions bokehjs/src/lib/core/util/ndarray.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {NDDataType, Arrayable} from "../types"
import {isObject, isNumber} from "./types"
import {isObject, isNumber, is_ArrayBufferLike} from "./types"
import {BYTE_ORDER} from "./platform"
import type {Equatable, Comparator} from "./eq"
import {equals} from "./eq"
Expand Down Expand Up @@ -30,7 +30,7 @@ export interface NDArrayType<T, U=T> extends Arrayable<U>, Equatable, Cloneable,
[i: number]: U
}

type Init<T> = number | ArrayBuffer | ArrayLike<T>
type Init<T> = number | ArrayBufferLike | ArrayLike<T>

export class BoolNDArray extends Uint8Array implements NDArrayType<boolean, number> {
readonly [__ndarray__] = true
Expand Down Expand Up @@ -308,7 +308,7 @@ export class ObjectNDArray<T=unknown> extends Array<T> implements NDArrayType<T>
}

constructor(init_: Init<T>, shape?: number[]) {
const init = init_ instanceof ArrayBuffer ? new Float64Array(init_) : init_
const init = is_ArrayBufferLike(init_) ? new Float64Array(init_) : init_
const size = isNumber(init) ? init : init.length

super(size)
Expand Down Expand Up @@ -376,11 +376,11 @@ export type Float32Array2d = Float32NDArray & Array2d
export type Float64Array2d = Float64NDArray & Array2d
export type FloatArray2d = Float32Array2d | Float64Array2d

export function ndarray<S extends number[]>(init: number | ArrayBuffer | ArrayLike<unknown>, options?: {shape?: S}): NDArrayTypes["object"]["ndarray"] & ArrayNd<S>
export function ndarray<K extends NDDataType, S extends number[]>(init: number | ArrayBuffer | ArrayLike<number>, options?: {dtype: K, shape?: S}): NDArrayTypes[K]["ndarray"] & ArrayNd<S>
export function ndarray<S extends number[]>(init: number | ArrayBufferLike | ArrayLike<unknown>, options?: {shape?: S}): NDArrayTypes["object"]["ndarray"] & ArrayNd<S>
export function ndarray<K extends NDDataType, S extends number[]>(init: number | ArrayBufferLike | ArrayLike<number>, options?: {dtype: K, shape?: S}): NDArrayTypes[K]["ndarray"] & ArrayNd<S>
export function ndarray<S extends number[]>(init: ArrayLike<unknown>, options?: {dtype: "object", shape?: S}): NDArrayTypes["object"]["ndarray"] & ArrayNd<S>

export function ndarray(init: number | ArrayBuffer | ArrayLike<unknown>, {dtype, shape}: {dtype?: NDDataType, shape?: number[]} = {}): NDArray {
export function ndarray(init: number | ArrayBufferLike | ArrayLike<unknown>, {dtype, shape}: {dtype?: NDDataType, shape?: number[]} = {}): NDArray {
if (dtype == null) {
dtype = (() => {
switch (true) {
Expand All @@ -391,9 +391,14 @@ export function ndarray(init: number | ArrayBuffer | ArrayLike<unknown>, {dtype,
case init instanceof Uint32Array: return "uint32"
case init instanceof Int32Array: return "int32"
case init instanceof Float32Array: return "float32"
case init instanceof ArrayBuffer:
case init instanceof Float64Array: return "float64"
default: return "object"
default: {
if (is_ArrayBufferLike(init)) {
return "float64"
} else {
return "object"
}
}
}
})()
}
Expand Down
5 changes: 5 additions & 0 deletions bokehjs/src/lib/core/util/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,8 @@ export function isIterable(obj: unknown): obj is Iterable<unknown> {
export function isArrayable(obj: unknown): obj is Arrayable<unknown> {
return isIterable(obj) && "length" in obj
}

export function is_ArrayBufferLike(obj: unknown): obj is ArrayBufferLike {
// SharedArrayBuffer is only available in cross origin isolated environments, otherwise it's undefined
return obj instanceof ArrayBuffer || (typeof SharedArrayBuffer !== "undefined" && obj instanceof SharedArrayBuffer)
}

0 comments on commit c829640

Please sign in to comment.