Skip to content

Commit 5b337ab

Browse files
committed
better typing for array types
1 parent 9e6d578 commit 5b337ab

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@rotu/structview",
3-
"version": "0.7.1",
3+
"version": "0.7.2",
44
"license": "MIT",
55
"tasks": {
66
"dev": "deno test --watch"

mod.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -427,10 +427,10 @@ export function defineStruct<const Props extends PropertyDescriptorMap>(
427427
* @param arrayOptions
428428
* @returns A new class, inheriting from `Struct` whose elements are statically typed structs
429429
*/
430-
export function defineArray<Ctor extends StructConstructor<object>>(
430+
export function defineArray<Item extends object>(
431431
arrayOptions: {
432432
/** Constructor for an object view of each item */
433-
struct: Ctor
433+
struct: StructConstructor<Item>
434434
/** Number of bytes between the start of consecutive items */
435435
byteStride: number
436436
/** Total number of items in the array (not bytes). If omitted, the array length will depend on the size of its underlying buffer */
@@ -439,8 +439,8 @@ export function defineArray<Ctor extends StructConstructor<object>>(
439439
): StructConstructor<
440440
{
441441
readonly length: number
442-
element(i: number): InstanceType<Ctor>
443-
} & Iterable<InstanceType<Ctor>>
442+
element(i: number): Item
443+
} & Iterable<Item>
444444
> {
445445
const { struct, byteStride, length } = arrayOptions
446446

@@ -464,7 +464,7 @@ export function defineArray<Ctor extends StructConstructor<object>>(
464464
* @param index
465465
* @returns a new struct instance viewing the item at the given index
466466
*/
467-
item(index: number) {
467+
item(index: number): Item {
468468
const ctor = this.#struct
469469
return new ctor(
470470
structBytes(
@@ -487,6 +487,5 @@ export function defineArray<Ctor extends StructConstructor<object>>(
487487
}
488488
}
489489
}
490-
// deno-lint-ignore no-explicit-any
491-
return StructArray as any
490+
return StructArray
492491
}

0 commit comments

Comments
 (0)