diff options
Diffstat (limited to 'util')
-rw-r--r-- | util/array.ts | 6 | ||||
-rw-r--r-- | util/types.ts | 8 |
2 files changed, 14 insertions, 0 deletions
diff --git a/util/array.ts b/util/array.ts index 5b8c512..f032935 100644 --- a/util/array.ts +++ b/util/array.ts @@ -6,6 +6,8 @@ declare global { peek(): T; /** @summary create Set from this array */ set(): Set<T>; + /** @summary clear array */ + clear(): void; } } @@ -21,3 +23,7 @@ Array.prototype.set = function() { return new Set(this); } +Array.prototype.clear = function() { + while (this.length > 0) this.pop(); +} + diff --git a/util/types.ts b/util/types.ts new file mode 100644 index 0000000..f03a242 --- /dev/null +++ b/util/types.ts @@ -0,0 +1,8 @@ +/** + * @type DeepPartial<T> makes all properties of type T optional, but keep + * array types intact + */ +export type DeepPartial<T> = { + [K in keyof T]?: T[K] extends Array<infer U> ? Array<U> : DeepPartial<T[K]>; +}; + |