typeshi 2.2.0 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -54,8 +54,7 @@ export declare function picked<T extends object, K extends keyof T>(obj: T, keys
54
54
  * - `'FIFO'` - remove elements from front (`'First-In-First-Out'`)
55
55
  * @note **assumes newest elements were pushed to end** i.e. `stack.push()` or `queue.enque()`
56
56
  * @param inPlace `boolean (optional)` `default = true`
57
- * - `true` - modify and return original array with: `arr.length = maxLength (LIFO)` or `arr.splice() (FIFO)`
58
- * - - if `'LIFO'`, can use JS trick by setting `arr.length = maxLength`
57
+ * - `true` - modify and return original array using: `arr.length = maxLength (LIFO)` or `arr.splice() (FIFO)`
59
58
  * - `false` - return new array with: `arr.slice()` `arr.slice(0, maxLength) (LIFO) or arr.slice(i, n) (FIFO)` where `n - i === maxLength`
60
59
  * @returns **`arr`** `T[]` where `arr.length <= maxLength`
61
60
  */
@@ -90,8 +90,7 @@ function picked(obj, keys) {
90
90
  * - `'FIFO'` - remove elements from front (`'First-In-First-Out'`)
91
91
  * @note **assumes newest elements were pushed to end** i.e. `stack.push()` or `queue.enque()`
92
92
  * @param inPlace `boolean (optional)` `default = true`
93
- * - `true` - modify and return original array with: `arr.length = maxLength (LIFO)` or `arr.splice() (FIFO)`
94
- * - - if `'LIFO'`, can use JS trick by setting `arr.length = maxLength`
93
+ * - `true` - modify and return original array using: `arr.length = maxLength (LIFO)` or `arr.splice() (FIFO)`
95
94
  * - `false` - return new array with: `arr.slice()` `arr.slice(0, maxLength) (LIFO) or arr.slice(i, n) (FIFO)` where `n - i === maxLength`
96
95
  * @returns **`arr`** `T[]` where `arr.length <= maxLength`
97
96
  */
@@ -116,7 +115,7 @@ function enforceMaxLength(arr, maxLength, principle = 'LIFO', inPlace = true) {
116
115
  if (principle === 'LIFO') {
117
116
  arr.length = maxLength;
118
117
  }
119
- else {
118
+ else { // 'FIFO'
120
119
  arr.splice(0, excess);
121
120
  }
122
121
  return arr;
@@ -125,7 +124,7 @@ function enforceMaxLength(arr, maxLength, principle = 'LIFO', inPlace = true) {
125
124
  if (principle === 'LIFO') {
126
125
  return arr.slice(0, maxLength);
127
126
  }
128
- else {
127
+ else { // 'FIFO'
129
128
  return arr.slice(excess);
130
129
  }
131
130
  }
@@ -261,7 +261,12 @@ export type PrimitiveKeys<T, Required extends boolean = false> = {
261
261
  export type Primitive = string | number | boolean | null | undefined;
262
262
  /** Get the union of all values of `T` (like `valueof T`) */
263
263
  export type ValueOf<T> = T[keyof T];
264
- /** Keys of `T` whose values extend a given type `U` */
265
- export type KeysOfType<T, U> = {
266
- [K in keyof T]: T[K] extends U ? K : never;
264
+ /**
265
+ * Keys of `T` whose values extend a given type `U`
266
+ * @template T - The object type
267
+ * @template U - The type to check each `T[K]` against
268
+ * @template Required - Whether the key is required (allows for `undefined` values if `false`) `default = false`
269
+ */
270
+ export type KeysOfType<T, U, Required extends boolean = false> = {
271
+ [K in keyof T]: Required extends true ? (T[K] extends U ? K : never) : (T[K] extends U | undefined ? K : never);
267
272
  }[keyof T][];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typeshi",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "description": "TypeScript utility modules",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",