@jakubmazanec/ts-utils 2.0.0-next.838299b → 2.1.0-9029e49

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.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # @jakubmazanec/ts-utils
4
4
 
5
- Collection of TypeScript types and utilities.
5
+ <!-- description -->Collection of TypeScript types and utilities.<!-- description -->
6
6
 
7
7
  </div>
8
8
 
@@ -9,18 +9,7 @@
9
9
  * type Result = IsEqual<{foo: string}, {foo: string}> // `typeof Result` is `true`
10
10
  * ```
11
11
  *
12
- * @typeParam A1 First type to compare
13
- * @typeParam A2 Second type to compare
12
+ * @typeParam T First type to compare
13
+ * @typeParam U Second type to compare
14
14
  */
15
- export type IsEqual<A1, A2> = IsStrictlyEqual<Unite<A1>, Unite<A2>>;
16
- /**
17
- * Helper type for {@linkcode IsEqual}.
18
- */
19
- type IsStrictlyEqual<A1, A2> = (<A>() => A extends A2 ? true : false) extends <A>() => A extends A1 ? true : false ? true : false;
20
- /**
21
- * Helper type for {@linkcode IsEqual}.
22
- */
23
- type Unite<T> = T extends Record<string, unknown> ? {
24
- [K in keyof T]: T[K];
25
- } : T;
26
- export {};
15
+ export type IsEqual<T, U> = (<G>() => G extends T ? 1 : 2) extends <G>() => G extends U ? 1 : 2 ? true : false;
@@ -9,8 +9,8 @@
9
9
  * type Result = IsEqual<{foo: string}, {foo: string}> // `typeof Result` is `true`
10
10
  * ```
11
11
  *
12
- * @typeParam A1 First type to compare
13
- * @typeParam A2 Second type to compare
12
+ * @typeParam T First type to compare
13
+ * @typeParam U Second type to compare
14
14
  */ export { };
15
15
 
16
16
  //# sourceMappingURL=IsEqual.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/types/IsEqual.ts"],"sourcesContent":["/**\n * Allows you to test if two types are the same:\n *\n * ```TypeScript\n * type Result = IsEqual<string, number> // `typeof Result` is `false`\n * ```\n *\n * ```TypeScript\n * type Result = IsEqual<{foo: string}, {foo: string}> // `typeof Result` is `true`\n * ```\n *\n * @typeParam A1 First type to compare\n * @typeParam A2 Second type to compare\n */\nexport type IsEqual<A1, A2> = IsStrictlyEqual<Unite<A1>, Unite<A2>>;\n\n/**\n * Helper type for {@linkcode IsEqual}.\n */\ntype IsStrictlyEqual<A1, A2> = (<A>() => A extends A2 ? true : false) extends <A>() => A extends A1\n ? true\n : false\n ? true\n : false;\n\n/**\n * Helper type for {@linkcode IsEqual}.\n */\ntype Unite<T> = T extends Record<string, unknown> ? {[K in keyof T]: T[K]} : T;\n"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;CAaC,GACD,WAc+E"}
1
+ {"version":3,"sources":["../../src/types/IsEqual.ts"],"sourcesContent":["/**\n * Allows you to test if two types are the same:\n *\n * ```TypeScript\n * type Result = IsEqual<string, number> // `typeof Result` is `false`\n * ```\n *\n * ```TypeScript\n * type Result = IsEqual<{foo: string}, {foo: string}> // `typeof Result` is `true`\n * ```\n *\n * @typeParam T First type to compare\n * @typeParam U Second type to compare\n */\nexport type IsEqual<T, U> = (<G>() => G extends T ? 1 : 2) extends <G>() => G extends U ? 1 : 2\n ? true\n : false;\n"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;CAaC,GACD,WAEU"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Maps all keys of type `T` to a new object type. Useful for converting interfaces to types or showing better hints from the language server.
3
+ *
4
+ * @typeParam T Base for the new type.
5
+ */
6
+ export type Simplify<T> = {
7
+ [KeyType in keyof T]: T[KeyType];
8
+ };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Maps all keys of type `T` to a new object type. Useful for converting interfaces to types or showing better hints from the language server.
3
+ *
4
+ * @typeParam T Base for the new type.
5
+ */ export { };
6
+
7
+ //# sourceMappingURL=Simplify.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/types/Simplify.ts"],"sourcesContent":["/**\n * Maps all keys of type `T` to a new object type. Useful for converting interfaces to types or showing better hints from the language server.\n *\n * @typeParam T Base for the new type.\n */\nexport type Simplify<T> = {[KeyType in keyof T]: T[KeyType]};\n"],"names":[],"mappings":"AAAA;;;;CAIC,GACD,WAA6D"}
@@ -5,6 +5,6 @@
5
5
  * type Result = TupleToUnion<['foo', 'bar']>; // `typeof Result` is `"foo" | "bar"`
6
6
  * ```
7
7
  *
8
- * @typeParam T Base for the new type
8
+ * @typeParam T Base for the new type.
9
9
  */
10
10
  export type TupleToUnion<T extends unknown[] | readonly unknown[]> = T[number];
@@ -5,7 +5,7 @@
5
5
  * type Result = TupleToUnion<['foo', 'bar']>; // `typeof Result` is `"foo" | "bar"`
6
6
  * ```
7
7
  *
8
- * @typeParam T Base for the new type
8
+ * @typeParam T Base for the new type.
9
9
  */ export { };
10
10
 
11
11
  //# sourceMappingURL=TupleToUnion.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/types/TupleToUnion.ts"],"sourcesContent":["/**\n * Converts tuple type to union type:\n *\n * ```TypeScript\n * type Result = TupleToUnion<['foo', 'bar']>; // `typeof Result` is `\"foo\" | \"bar\"`\n * ```\n *\n * @typeParam T Base for the new type\n */\nexport type TupleToUnion<T extends unknown[] | readonly unknown[]> = T[number];\n"],"names":[],"mappings":"AAAA;;;;;;;;CAQC,GACD,WAA+E"}
1
+ {"version":3,"sources":["../../src/types/TupleToUnion.ts"],"sourcesContent":["/**\n * Converts tuple type to union type:\n *\n * ```TypeScript\n * type Result = TupleToUnion<['foo', 'bar']>; // `typeof Result` is `\"foo\" | \"bar\"`\n * ```\n *\n * @typeParam T Base for the new type.\n */\nexport type TupleToUnion<T extends unknown[] | readonly unknown[]> = T[number];\n"],"names":[],"mappings":"AAAA;;;;;;;;CAQC,GACD,WAA+E"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Create a new type that removes `readonly` from object types's keys. Inverse of {@linkcode Readonly<T>}.
3
+ */
4
+ export type Writable<T> = {
5
+ -readonly [K in keyof T]: T[K];
6
+ };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Create a new type that removes `readonly` from object types's keys. Inverse of {@linkcode Readonly<T>}.
3
+ */ export { };
4
+
5
+ //# sourceMappingURL=Writable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/types/Writable.ts"],"sourcesContent":["/**\n * Create a new type that removes `readonly` from object types's keys. Inverse of {@linkcode Readonly<T>}.\n */\nexport type Writable<T> = {\n -readonly [K in keyof T]: T[K];\n};\n"],"names":[],"mappings":"AAAA;;CAEC,GACD,WAEE"}
package/dist/types.d.ts CHANGED
@@ -11,5 +11,7 @@ export * from './types/Parameters.js';
11
11
  export * from './types/Primitive.js';
12
12
  export * from './types/RequiredKeys.js';
13
13
  export * from './types/ReturnType.js';
14
+ export * from './types/Simplify.js';
14
15
  export * from './types/TupleToUnion.js';
15
16
  export * from './types/UnionToIntersection.js';
17
+ export * from './types/Writable.js';
package/dist/types.js CHANGED
@@ -11,7 +11,9 @@ export * from './types/Parameters.js';
11
11
  export * from './types/Primitive.js';
12
12
  export * from './types/RequiredKeys.js';
13
13
  export * from './types/ReturnType.js';
14
+ export * from './types/Simplify.js';
14
15
  export * from './types/TupleToUnion.js';
15
16
  export * from './types/UnionToIntersection.js';
17
+ export * from './types/Writable.js';
16
18
 
17
19
  //# sourceMappingURL=types.js.map
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/types.ts"],"sourcesContent":["export * from './types/AtLeastOneRequired.js';\nexport * from './types/DeepPartial.js';\nexport * from './types/DeepReadonly.js';\nexport * from './types/If.js';\nexport * from './types/IsEqual.js';\nexport * from './types/LiteralUnion.js';\nexport * from './types/NonArray.js';\nexport * from './types/NonArrayLike.js';\nexport * from './types/OptionalKeys.js';\nexport * from './types/Parameters.js';\nexport * from './types/Primitive.js';\nexport * from './types/RequiredKeys.js';\nexport * from './types/ReturnType.js';\nexport * from './types/TupleToUnion.js';\nexport * from './types/UnionToIntersection.js';\n"],"names":[],"mappings":"AAAA,cAAc,gCAAgC;AAC9C,cAAc,yBAAyB;AACvC,cAAc,0BAA0B;AACxC,cAAc,gBAAgB;AAC9B,cAAc,qBAAqB;AACnC,cAAc,0BAA0B;AACxC,cAAc,sBAAsB;AACpC,cAAc,0BAA0B;AACxC,cAAc,0BAA0B;AACxC,cAAc,wBAAwB;AACtC,cAAc,uBAAuB;AACrC,cAAc,0BAA0B;AACxC,cAAc,wBAAwB;AACtC,cAAc,0BAA0B;AACxC,cAAc,iCAAiC"}
1
+ {"version":3,"sources":["../src/types.ts"],"sourcesContent":["export * from './types/AtLeastOneRequired.js';\nexport * from './types/DeepPartial.js';\nexport * from './types/DeepReadonly.js';\nexport * from './types/If.js';\nexport * from './types/IsEqual.js';\nexport * from './types/LiteralUnion.js';\nexport * from './types/NonArray.js';\nexport * from './types/NonArrayLike.js';\nexport * from './types/OptionalKeys.js';\nexport * from './types/Parameters.js';\nexport * from './types/Primitive.js';\nexport * from './types/RequiredKeys.js';\nexport * from './types/ReturnType.js';\nexport * from './types/Simplify.js';\nexport * from './types/TupleToUnion.js';\nexport * from './types/UnionToIntersection.js';\nexport * from './types/Writable.js';\n"],"names":[],"mappings":"AAAA,cAAc,gCAAgC;AAC9C,cAAc,yBAAyB;AACvC,cAAc,0BAA0B;AACxC,cAAc,gBAAgB;AAC9B,cAAc,qBAAqB;AACnC,cAAc,0BAA0B;AACxC,cAAc,sBAAsB;AACpC,cAAc,0BAA0B;AACxC,cAAc,0BAA0B;AACxC,cAAc,wBAAwB;AACtC,cAAc,uBAAuB;AACrC,cAAc,0BAA0B;AACxC,cAAc,wBAAwB;AACtC,cAAc,sBAAsB;AACpC,cAAc,0BAA0B;AACxC,cAAc,iCAAiC;AAC/C,cAAc,sBAAsB"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/assert.ts"],"sourcesContent":["/**\n * A subclass of `Error` that indicates an assertion failure.\n */\nexport class AssertionError extends Error {\n /**\n * @param message Message added to the default error message\n */\n constructor(message?: string) {\n super(`Wrong assertion encountered${message ? `: \"${message}\"` : ''}!`);\n\n this.name = 'AssertionError';\n }\n}\n\n/**\n * A function that throws {@linkcode AssertionError} (with optional message defined with `errorMessage`) if\n * `condition` is falsy.\n * You can use it to narrow types:\n *\n * ```TypeScript\n * interface Foo {\n * kind: 'Foo';\n * }\n *\n * interface Bar {\n * kind: 'Bar';\n * }\n *\n * declare const foobar: Foo | Bar;\n *\n * assert(is<Foo>(foobar, foobar.kind === 'Foo'));\n *\n * // `typeof foobar` is now `Foo`\n * ```\n *\n * @param condition Condition we're asserting isn't falsy\n * @param errorMessage Message for the `AssertionError`\n */\nexport function assert(condition: unknown, errorMessage?: string): asserts condition {\n // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions -- we don't mind here\n if (!condition) {\n throw new AssertionError(errorMessage);\n }\n}\n"],"names":["AssertionError","Error","constructor","message","name","assert","condition","errorMessage"],"mappings":"AAAA;;CAEC,GACD,OAAO,MAAMA,uBAAuBC;IAClC;;GAEC,GACDC,YAAYC,OAAgB,CAAE;QAC5B,KAAK,CAAC,CAAC,2BAA2B,EAAEA,UAAU,CAAC,GAAG,EAAEA,QAAQ,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QAEtE,IAAI,CAACC,IAAI,GAAG;IACd;AACF,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;CAuBC,GACD,OAAO,SAASC,OAAOC,SAAkB,EAAEC,YAAqB,EAAqB;IACnF,+FAA+F;IAC/F,IAAI,CAACD,WAAW;QACd,MAAM,IAAIN,eAAeO,cAAc;IACzC,CAAC;AACH,CAAC"}
1
+ {"version":3,"sources":["../../src/utils/assert.ts"],"sourcesContent":["/**\n * A subclass of `Error` that indicates an assertion failure.\n */\nexport class AssertionError extends Error {\n /**\n * @param message Message added to the default error message\n */\n constructor(message?: string) {\n super(`Wrong assertion encountered${message ? `: \"${message}\"` : ''}!`);\n\n this.name = 'AssertionError';\n }\n}\n\n/**\n * A function that throws {@linkcode AssertionError} (with optional message defined with `errorMessage`) if\n * `condition` is falsy.\n * You can use it to narrow types:\n *\n * ```TypeScript\n * interface Foo {\n * kind: 'Foo';\n * }\n *\n * interface Bar {\n * kind: 'Bar';\n * }\n *\n * declare const foobar: Foo | Bar;\n *\n * assert(is<Foo>(foobar, foobar.kind === 'Foo'));\n *\n * // `typeof foobar` is now `Foo`\n * ```\n *\n * @param condition Condition we're asserting isn't falsy\n * @param errorMessage Message for the `AssertionError`\n */\nexport function assert(condition: unknown, errorMessage?: string): asserts condition {\n // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions -- we don't mind here\n if (!condition) {\n throw new AssertionError(errorMessage);\n }\n}\n"],"names":["AssertionError","Error","constructor","message","name","assert","condition","errorMessage"],"mappings":"AAAA;;CAEC,GACD,OAAO,MAAMA,uBAAuBC;IAClC;;GAEC,GACDC,YAAYC,OAAgB,CAAE;QAC5B,KAAK,CAAC,CAAC,2BAA2B,EAAEA,UAAU,CAAC,GAAG,EAAEA,QAAQ,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC;QAEtE,IAAI,CAACC,OAAO;IACd;AACF;AAEA;;;;;;;;;;;;;;;;;;;;;;;CAuBC,GACD,OAAO,SAASC,OAAOC,SAAkB,EAAEC,YAAqB;IAC9D,+FAA+F;IAC/F,IAAI,CAACD,WAAW;QACd,MAAM,IAAIN,eAAeO;IAC3B;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/is.ts"],"sourcesContent":["/**\n * A generic type guard. If `isMatched` is `true`, TypeScript assumes `value` is of type `T`.\n * You can use it to narrow types:\n *\n * ```TypeScript\n * interface Foo {\n * value: string;\n * }\n *\n * interface Bar {\n * value: number;\n * }\n *\n * declare let foobar: Foo | Bar;\n *\n * if (is<Foo>(foobar, typeof foobar.value === 'string')) {\n * // `typeof foobar` is now `Foo`\n * } else {\n * // `typeof foobar` is now `Bar`\n * }\n * ```\n *\n * @typeParam T Potential type of `value`\n * @param value Value being checked\n * @param isMatched Specifies if `value` is of type `T`\n * @return Value of `isMatched`\n */\nexport function is<T>(value: unknown, isMatched: boolean): value is T {\n return isMatched;\n}\n"],"names":["is","value","isMatched"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;CA0BC,GACD,OAAO,SAASA,GAAMC,KAAc,EAAEC,SAAkB,EAAc;IACpE,OAAOA;AACT,CAAC"}
1
+ {"version":3,"sources":["../../src/utils/is.ts"],"sourcesContent":["/**\n * A generic type guard. If `isMatched` is `true`, TypeScript assumes `value` is of type `T`.\n * You can use it to narrow types:\n *\n * ```TypeScript\n * interface Foo {\n * value: string;\n * }\n *\n * interface Bar {\n * value: number;\n * }\n *\n * declare let foobar: Foo | Bar;\n *\n * if (is<Foo>(foobar, typeof foobar.value === 'string')) {\n * // `typeof foobar` is now `Foo`\n * } else {\n * // `typeof foobar` is now `Bar`\n * }\n * ```\n *\n * @typeParam T Potential type of `value`\n * @param value Value being checked\n * @param isMatched Specifies if `value` is of type `T`\n * @return Value of `isMatched`\n */\nexport function is<T>(value: unknown, isMatched: boolean): value is T {\n return isMatched;\n}\n"],"names":["is","value","isMatched"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;CA0BC,GACD,OAAO,SAASA,GAAMC,KAAc,EAAEC,SAAkB;IACtD,OAAOA;AACT"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/isNonNullable.ts"],"sourcesContent":["/**\n * A type guard that checks whether variable is not `null` or `undefined`:\n *\n * ```TypeScript\n * declare let foobar: string | null;\n *\n * if (isNonNullable(foobar)) {\n * // `typeof foobar` is now `string`\n * } else {\n * // `typeof foobar` is now `null`\n * }\n * ```\n *\n * @typeParam T Type of `value`\n * @param value Value being checked\n * @return `true` if `value` is non-nullable\n */\nexport function isNonNullable<T>(value: T): value is NonNullable<T> {\n return value !== undefined && value !== null;\n}\n"],"names":["isNonNullable","value","undefined"],"mappings":"AAAA;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,SAASA,cAAiBC,KAAQ,EAA2B;IAClE,OAAOA,UAAUC,aAAaD,UAAU,IAAI;AAC9C,CAAC"}
1
+ {"version":3,"sources":["../../src/utils/isNonNullable.ts"],"sourcesContent":["/**\n * A type guard that checks whether variable is not `null` or `undefined`:\n *\n * ```TypeScript\n * declare let foobar: string | null;\n *\n * if (isNonNullable(foobar)) {\n * // `typeof foobar` is now `string`\n * } else {\n * // `typeof foobar` is now `null`\n * }\n * ```\n *\n * @typeParam T Type of `value`\n * @param value Value being checked\n * @return `true` if `value` is non-nullable\n */\nexport function isNonNullable<T>(value: T): value is NonNullable<T> {\n return value !== undefined && value !== null;\n}\n"],"names":["isNonNullable","value","undefined"],"mappings":"AAAA;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,SAASA,cAAiBC,KAAQ;IACvC,OAAOA,UAAUC,aAAaD,UAAU;AAC1C"}
@@ -0,0 +1,2 @@
1
+ import { type Primitive } from '../types.js';
2
+ export declare function tuple<T extends Array<Primitive | {}>>(...values: T): T;
@@ -0,0 +1,6 @@
1
+ // eslint-disable-next-line @typescript-eslint/ban-types -- this is intended
2
+ export function tuple(...values) {
3
+ return values;
4
+ }
5
+
6
+ //# sourceMappingURL=tuple.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/tuple.ts"],"sourcesContent":["import {type Primitive} from '../types.js';\n\n// eslint-disable-next-line @typescript-eslint/ban-types -- this is intended\nexport function tuple<T extends Array<Primitive | {}>>(...values: T) {\n return values;\n}\n"],"names":["tuple","values"],"mappings":"AAEA,4EAA4E;AAC5E,OAAO,SAASA,MAAuC,GAAGC,MAAS;IACjE,OAAOA;AACT"}
package/dist/utils.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './utils/assert.js';
2
2
  export * from './utils/is.js';
3
3
  export * from './utils/isNonNullable.js';
4
+ export * from './utils/tuple.js';
package/dist/utils.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './utils/assert.js';
2
2
  export * from './utils/is.js';
3
3
  export * from './utils/isNonNullable.js';
4
+ export * from './utils/tuple.js';
4
5
 
5
6
  //# sourceMappingURL=utils.js.map
package/dist/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/utils.ts"],"sourcesContent":["export * from './utils/assert.js';\nexport * from './utils/is.js';\nexport * from './utils/isNonNullable.js';\n"],"names":[],"mappings":"AAAA,cAAc,oBAAoB;AAClC,cAAc,gBAAgB;AAC9B,cAAc,2BAA2B"}
1
+ {"version":3,"sources":["../src/utils.ts"],"sourcesContent":["export * from './utils/assert.js';\nexport * from './utils/is.js';\nexport * from './utils/isNonNullable.js';\nexport * from './utils/tuple.js';\n"],"names":[],"mappings":"AAAA,cAAc,oBAAoB;AAClC,cAAc,gBAAgB;AAC9B,cAAc,2BAA2B;AACzC,cAAc,mBAAmB"}
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@jakubmazanec/ts-utils",
3
- "version": "2.0.0-next.838299b",
3
+ "version": "2.1.0-9029e49",
4
4
  "description": "Collection of TypeScript types and utilities.",
5
5
  "repository": {
6
6
  "type": "git",
7
- "url": "git@github.com:jakubmazanec/js-tools.git",
7
+ "url": "https://github.com/jakubmazanec/js-tools",
8
8
  "directory": "packages/ts-utils"
9
9
  },
10
10
  "license": "LGPL-3.0-only",
@@ -9,21 +9,9 @@
9
9
  * type Result = IsEqual<{foo: string}, {foo: string}> // `typeof Result` is `true`
10
10
  * ```
11
11
  *
12
- * @typeParam A1 First type to compare
13
- * @typeParam A2 Second type to compare
12
+ * @typeParam T First type to compare
13
+ * @typeParam U Second type to compare
14
14
  */
15
- export type IsEqual<A1, A2> = IsStrictlyEqual<Unite<A1>, Unite<A2>>;
16
-
17
- /**
18
- * Helper type for {@linkcode IsEqual}.
19
- */
20
- type IsStrictlyEqual<A1, A2> = (<A>() => A extends A2 ? true : false) extends <A>() => A extends A1
21
- ? true
22
- : false
15
+ export type IsEqual<T, U> = (<G>() => G extends T ? 1 : 2) extends <G>() => G extends U ? 1 : 2
23
16
  ? true
24
17
  : false;
25
-
26
- /**
27
- * Helper type for {@linkcode IsEqual}.
28
- */
29
- type Unite<T> = T extends Record<string, unknown> ? {[K in keyof T]: T[K]} : T;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Maps all keys of type `T` to a new object type. Useful for converting interfaces to types or showing better hints from the language server.
3
+ *
4
+ * @typeParam T Base for the new type.
5
+ */
6
+ export type Simplify<T> = {[KeyType in keyof T]: T[KeyType]};
@@ -5,6 +5,6 @@
5
5
  * type Result = TupleToUnion<['foo', 'bar']>; // `typeof Result` is `"foo" | "bar"`
6
6
  * ```
7
7
  *
8
- * @typeParam T Base for the new type
8
+ * @typeParam T Base for the new type.
9
9
  */
10
10
  export type TupleToUnion<T extends unknown[] | readonly unknown[]> = T[number];
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Create a new type that removes `readonly` from object types's keys. Inverse of {@linkcode Readonly<T>}.
3
+ */
4
+ export type Writable<T> = {
5
+ -readonly [K in keyof T]: T[K];
6
+ };
package/src/types.ts CHANGED
@@ -11,5 +11,7 @@ export * from './types/Parameters.js';
11
11
  export * from './types/Primitive.js';
12
12
  export * from './types/RequiredKeys.js';
13
13
  export * from './types/ReturnType.js';
14
+ export * from './types/Simplify.js';
14
15
  export * from './types/TupleToUnion.js';
15
16
  export * from './types/UnionToIntersection.js';
17
+ export * from './types/Writable.js';
@@ -0,0 +1,6 @@
1
+ import {type Primitive} from '../types.js';
2
+
3
+ // eslint-disable-next-line @typescript-eslint/ban-types -- this is intended
4
+ export function tuple<T extends Array<Primitive | {}>>(...values: T) {
5
+ return values;
6
+ }
package/src/utils.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './utils/assert.js';
2
2
  export * from './utils/is.js';
3
3
  export * from './utils/isNonNullable.js';
4
+ export * from './utils/tuple.js';