From 1af6f78fa9ce27e27ce93aee423de6ce4950be55 Mon Sep 17 00:00:00 2001 From: Karsten Schmidt Date: Tue, 4 Jun 2019 19:00:24 +0100 Subject: [PATCH] feat(vector-pools): enable TS strict compiler flags (refactor) - add missing type hints/return types --- packages/vector-pools/src/api.ts | 6 ++--- packages/vector-pools/src/convert.ts | 4 ++-- packages/vector-pools/src/linked-list.ts | 29 +++++++++++++++--------- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/packages/vector-pools/src/api.ts b/packages/vector-pools/src/api.ts index 42db350b9e..0c8d5e88ed 100644 --- a/packages/vector-pools/src/api.ts +++ b/packages/vector-pools/src/api.ts @@ -41,7 +41,7 @@ export interface IVecPool extends IRelease { free(vec: StridedVec | TypedArray): boolean; - freeAll(); + freeAll(): void; } export type VecFactory = ( @@ -72,7 +72,7 @@ export const enum GLType { /** * Conversion from `GLType` to `Type`. */ -export const GL2TYPE = { +export const GL2TYPE: { [id: number]: Type } = { [GLType.I8]: Type.I8, [GLType.U8]: Type.U8, [GLType.I16]: Type.I16, @@ -86,7 +86,7 @@ export const GL2TYPE = { /** * Conversion from `Type` to `GLType`. */ -export const TYPE2GL = { +export const TYPE2GL: { [id: number]: GLType } = { [Type.I8]: GLType.I8, [Type.U8]: GLType.U8, [Type.I16]: GLType.I16, diff --git a/packages/vector-pools/src/convert.ts b/packages/vector-pools/src/convert.ts index fa136c76d6..7b03f0863c 100644 --- a/packages/vector-pools/src/convert.ts +++ b/packages/vector-pools/src/convert.ts @@ -14,10 +14,10 @@ import { GL2TYPE, GLType, TYPE2GL } from "./api"; */ export const asNativeType = (type: GLType | Type): Type => { const t = GL2TYPE[type]; - return t !== undefined ? t : type; + return t !== undefined ? t : type; }; export const asGLType = (type: GLType | Type): GLType => { const t = TYPE2GL[type]; - return t !== undefined ? t : type; + return t !== undefined ? t : type; }; diff --git a/packages/vector-pools/src/linked-list.ts b/packages/vector-pools/src/linked-list.ts index b515f52bdd..745d8941f5 100644 --- a/packages/vector-pools/src/linked-list.ts +++ b/packages/vector-pools/src/linked-list.ts @@ -2,9 +2,16 @@ import { StridedVec, Vec } from "@thi.ng/vectors"; import { AVecList } from "./alist"; import { VecFactory } from "./api"; +interface Cell { + prev: CellVec; + next: CellVec; +} + +type CellVec = T & Cell; + export class VecLinkedList extends AVecList { - head: T; - tail: T; + head: CellVec; + tail: CellVec; readonly closed: boolean; protected _length: number; @@ -39,7 +46,7 @@ export class VecLinkedList extends AVecList { *[Symbol.iterator]() { if (this._length) { - let v: any = this.head; + let v = this.head; const first = v; do { yield v; @@ -53,15 +60,15 @@ export class VecLinkedList extends AVecList { } add(): T { - const v: any = this.alloc(); + const v = >this.alloc(); if (v) { if (this.tail) { v.prev = this.tail; - (this.tail).next = v; + this.tail.next = v; this.tail = v; if (this.closed) { v.next = this.head; - (this.head).prev = v; + this.head.prev = v; } this._length++; } else { @@ -77,9 +84,9 @@ export class VecLinkedList extends AVecList { if (!this._length) { return i === 0 ? this.add() : undefined; } - const q: any = this.nth(i); + const q = >this.nth(i); if (!q) return; - const v: any = this.alloc(); + const v = >this.alloc(); if (v) { if (this.head === q) { this.head = v; @@ -99,7 +106,7 @@ export class VecLinkedList extends AVecList { if (this.has(vec)) { this._length--; this.freeIDs.push(vec.offset); - const v: any = vec; + const v = >vec; if (v.prev) { v.prev.next = v.next; } @@ -119,7 +126,7 @@ export class VecLinkedList extends AVecList { } has(value: T) { - let v: any = this.head; + let v = this.head; const first = v; do { if (v === value) { @@ -130,7 +137,7 @@ export class VecLinkedList extends AVecList { return false; } - nth(n: number): T { + nth(n: number): T | undefined { if (n < 0) { n += this._length; }