assertie 0.3.2 → 1.0.0

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/CHANGELOG.md CHANGED
@@ -1,8 +1,31 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.0.0](https://github.com/OfficialHalfwayDead/assertie/compare/v0.3.2...v1.0.0) (2026-02-15)
4
+
5
+ ### Breaking Changes
6
+
7
+ * [`a04c1be`](https://github.com/OfficialHalfwayDead/assertie/commit/a04c1be1f86d6280ce925dff8c5b0fdef6811660) Rename AssertionError to AssertieError to reduce the likelihood of name conflicts.
8
+ * [`e91af47`](https://github.com/OfficialHalfwayDead/assertie/commit/e91af47062b6255dd415b5fcbbd6768ac836beb4) Changed the type that functions get narrowed to, so that they return `unknown` when called instead of `any`. This only affects cases where the TypeScript has no other way of inferring the true return type.
9
+
10
+ ### Features
11
+
12
+ * [`2c021d7`](https://github.com/OfficialHalfwayDead/assertie/commit/2c021d7796e1d1e1663f0149d3ada35d9f0b744d) Enable passing abstract classes to `assertType` and `assertInstanceOf`.
13
+ * [`f307a3f`](https://github.com/OfficialHalfwayDead/assertie/commit/f307a3f28fe8dbb9b2f992578fda796006839dd3) Improve `assertIsTuple` narrowing. The narrowed type now results in TypeScript errors when trying to read/write to an index higher than the asserted tuple length.
14
+ * [`d76b312`](https://github.com/OfficialHalfwayDead/assertie/commit/d76b31211e0e5e91673a3d2ac84b2088ba00d89d) Allow passing readonly arrays and tuples and preserve their readonlyness. Objects with readonly params were already working.
15
+
16
+ ### Other
17
+
18
+ * [`2a91906`](https://github.com/OfficialHalfwayDead/assertie/commit/2a9190653f6c32efca5a5abf7e951e0635608f30) Add runtime tests for all assertion functions and internal helpers.
19
+ * [`e91af47`](https://github.com/OfficialHalfwayDead/assertie/commit/e91af47062b6255dd415b5fcbbd6768ac836beb4) Add type tests for the type narrowing of assertions.
20
+ * [`b24849e`](https://github.com/OfficialHalfwayDead/assertie/commit/b24849eeb9bc6db291d95212b3cfa736d2136c3d) Bugfix: Internal functions getTypeNameOfUnknown and isType
21
+ * Fix issues where getTypeNameOfUnknown returns an underspecified or
22
+ unexpected type, leading to assertions with poor error messages.
23
+ * Fix an issue where isType throws instead of returning false, leading to assertions throwing an exception of the wrong type with a poor error message.
24
+ * [`7c8ffd3`](https://github.com/OfficialHalfwayDead/assertie/commit/7c8ffd33771e38f9f8fe95e4bff62a3f96edd0df) Improve Svelte pitfalls explanation in README.
25
+
3
26
  ## [0.3.2](https://github.com/OfficialHalfwayDead/assertie/compare/v0.3.1...v0.3.2) (2025-02-27)
4
27
 
5
- * [`0814dd2`](https://github.com/OfficialHalfwayDead/assertie/commit/0814dd2a6b9daf2bbeb99e2925710cc8a76caf07) Bugfix: Constructor type wasn't properly typed and prevent `assertInstanceOf` and `assertType` from accepting many construcable types.
28
+ * [`0814dd2`](https://github.com/OfficialHalfwayDead/assertie/commit/0814dd2a6b9daf2bbeb99e2925710cc8a76caf07) Bugfix: Constructor type wasn't properly typed and prevented `assertInstanceOf` and `assertType` from accepting many constructible types.
6
29
  * [`940e4e4`](https://github.com/OfficialHalfwayDead/assertie/commit/940e4e424c14db20734ed4e2ec2b8a6eeae3aef3) Clarify SSR vite settings and Svelte/Proxy pitfalls in the README.
7
30
 
8
31
 
@@ -2,6 +2,19 @@
2
2
 
3
3
  Scroll down to your previous version and then follow all the steps upwards in order until the version you're targeting.
4
4
 
5
+ ## [0.3.x to 1.0.0](https://github.com/OfficialHalfwayDead/assertie/compare/v0.3.2...v1.0.0)
6
+
7
+ * When narrowing a complete unknown to a function, the type has changed so that when called, the function returns `unknown` when called instead of `any`.
8
+ ```ts
9
+ const fn = () => 5 as unknown;
10
+ assertType(fn, "function");
11
+ fn(); // allowed
12
+ const res: string = fn(); // no longer valid since unknown can't be assigned to string
13
+ ```
14
+ This only affects cases where the TypeScript has no other way of inferring the true return type.
15
+
16
+ * If you were relying on the name/type of the error thrown by the assertions, it has been changed from `AssertionError` to `AssertieError` to prevent name conflicts.
17
+
5
18
  ## [0.2.x to 0.3.0](https://github.com/OfficialHalfwayDead/assertie/compare/v0.2.0...v0.3.0)
6
19
 
7
20
  * New features mean assertie >= 0.3.0 requires TypeScript 4.7.0 or higher in your project. (Previous minimum version was 3.7.0)
package/README.md CHANGED
@@ -19,7 +19,7 @@ if (original === null) return;
19
19
  const clone = original.cloneNode(true);
20
20
  assertInstanceOf(clone, HTMLElement);
21
21
  // Unlike casting, the assert will throw if you were mistaken,
22
- // or if someone accidentally changed const original = document;
22
+ // or if someone changes const original = document;
23
23
  clone.innerText = "No `as` cast needed! 0 overhead in production.";
24
24
  ```
25
25
 
@@ -48,7 +48,7 @@ const config: UserConfig = {
48
48
 
49
49
  If you're getting errors when using the package, it's likely because your TypeScript targets are too low:
50
50
 
51
- ```json
51
+ ```jsonc
52
52
  // tsconfig.json
53
53
  {
54
54
  "compilerOptions": {
@@ -135,7 +135,7 @@ f();
135
135
 
136
136
  There are multiple advantages to using an assertion in this case:
137
137
 
138
- It clarifies the code's intent. f was never meant to conditionally execute its body. It is always supposed to work, but the if statement was required to satisfy the compiler.
138
+ 1. It clarifies the code's intent. f was never meant to conditionally execute its body. It is always supposed to work, but the if statement was required to satisfy the compiler.
139
139
  2. The assert will throw an error in dev if the case that should never happen does happen. Without the assert, any potential behavior change due to `hoisted` not being set is more likely to go unnoticed.
140
140
  3. It's a little shorter, mainly if you have to check null and undefined and maybe have prettier rules for { brackets } on if statements.
141
141
  4. The assert will be removed in production, so there's no overhead. If that makes you uncomfortable, you can just can still put the if statement below the assert and reap the benefits of the first two points.
@@ -253,11 +253,23 @@ assert(/* @__PURE__ */ object.foo() === "yup");
253
253
 
254
254
  ### Svelte
255
255
 
256
- Accessing the value of a rune `x` compiles to `get(x)`, leading to the same pitfall as above. To prevent this, you need to treat the rune like a function:
256
+ Runes in Svelte are, in reality, proxy objects, with those details hidden from the user by the compiler. Accessing `x` compiles to `get(x)`, which leads to the same pitfall as above. The cleanest solution is to create a local copy when possible:
257
257
 
258
258
  ```ts
259
259
  let rune = $state(1);
260
- let otherRune = $state(1);
261
260
 
262
- assert(/*@__PURE__*/ rune === /*@__PURE__*/ otherRune);
261
+ // ... local context
262
+ const lcopy = $state.snapshot(rune); // stays
263
+ assertType(lcopy, "string"); // removed by vite in prod
264
+ // only lcopy gets type narrowing, not rune
263
265
  ```
266
+
267
+ Be aware that, by definition, the snapshot is a regular object, and therefore will not be reactive.
268
+
269
+ In theory, you can also cheat by marking the rune as a pure function when accessing it:
270
+
271
+ ```ts
272
+ assertType(/* @__PURE__ */ rune, "string"); // dangerous
273
+ ```
274
+
275
+ Even with side-effect-free getters, this usage can cause diverging behavior between dev and prod if the Svelte compiler is in a tracking context such as `$effect()`. If you intend to use it this way, you should be absolutely certain that you understand the details of Svelte's behavior.
@@ -0,0 +1,20 @@
1
+ import { AllJSTypes, ResolveAnyJSType } from "./types";
2
+ /**
3
+ * Gets the display name of an expected type for error messages.
4
+ * @param {AllJSTypes} expectedType - The expected type value.
5
+ * @returns {string} The normalized name of the expected type.
6
+ */
7
+ export declare function getNameOfExpectedType(expectedType: AllJSTypes): string;
8
+ /**
9
+ * Gets the runtime type name of an unknown item for error messages.
10
+ * @param {unknown} item - The item whose runtime type name should be determined.
11
+ * @returns {string} The runtime type name of item.
12
+ */
13
+ export declare function getTypeNameOfUnknown(item: unknown): string;
14
+ /**
15
+ * Checks whether the provided item is of the expectedType.
16
+ * @param {unknown} item - The item to check.
17
+ * @param {AllJSTypes} expectedType - The expected type to check against.
18
+ * @returns {boolean} `true` if item's type matches expectedType.
19
+ */
20
+ export declare function isType<T extends AllJSTypes>(item: unknown, expectedType: T): item is ResolveAnyJSType<T>;
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Gets the display name of an expected type for error messages.
3
+ * @param {AllJSTypes} expectedType - The expected type value.
4
+ * @returns {string} The normalized name of the expected type.
5
+ */
6
+ export function getNameOfExpectedType(expectedType) {
7
+ if (expectedType === null)
8
+ return "null";
9
+ if (expectedType === undefined)
10
+ return "undefined";
11
+ if (typeof expectedType === "string")
12
+ return expectedType;
13
+ return expectedType.name;
14
+ }
15
+ /**
16
+ * Gets the runtime type name of an unknown item for error messages.
17
+ * @param {unknown} item - The item whose runtime type name should be determined.
18
+ * @returns {string} The runtime type name of item.
19
+ */
20
+ export function getTypeNameOfUnknown(item) {
21
+ if (item === null)
22
+ return "null";
23
+ const type = typeof item;
24
+ switch (type) {
25
+ case "object":
26
+ case "function":
27
+ try {
28
+ const unsafe = item; // We are using try catch for the fail cases
29
+ if (unsafe instanceof unsafe.constructor) {
30
+ return unsafe.constructor.name;
31
+ }
32
+ }
33
+ catch {
34
+ }
35
+ const typeStr = Object.prototype.toString.call(item);
36
+ return typeStr.slice(8, -1); // "[object Type]" -> "Type"
37
+ default:
38
+ return type;
39
+ }
40
+ }
41
+ /**
42
+ * Checks whether the provided item is of the expectedType.
43
+ * @param {unknown} item - The item to check.
44
+ * @param {AllJSTypes} expectedType - The expected type to check against.
45
+ * @returns {boolean} `true` if item's type matches expectedType.
46
+ */
47
+ export function isType(item, expectedType) {
48
+ if (typeof item === expectedType)
49
+ return true; // correct primitive type
50
+ // Now, if the expectedType is a PrimitiveTypeString,
51
+ // the item is guaranteed to be of the wrong type since it didn't match the typeof check above
52
+ if (typeof expectedType === "string")
53
+ return false;
54
+ const expectedUndefNullOrConstructor = expectedType;
55
+ // The type restriction on T guarantees that item is now either undefined, null, or a constructor
56
+ if (item === expectedUndefNullOrConstructor)
57
+ return true; // correct undefined, null, or constructor of itself
58
+ // i.e. const MyType = Date; isType(Date, Date) && isType(MyType, Date) are both true
59
+ if (expectedUndefNullOrConstructor === null || expectedUndefNullOrConstructor === undefined)
60
+ return false;
61
+ const expectedConstructor = expectedType;
62
+ // Lastly, check if the item is an instance of the provided constructor
63
+ if (item instanceof expectedConstructor)
64
+ return true;
65
+ return false;
66
+ }
package/lib/index.d.ts CHANGED
@@ -1,162 +1,155 @@
1
- declare type Tuple<T, N extends number, A extends unknown[] = []> = A["length"] extends N ? A : Tuple<T, N, [...A, T]>;
2
- declare type PrimitiveTypes = {
3
- "string": string;
4
- "number": number;
5
- "boolean": boolean;
6
- "bigint": bigint;
7
- "undefined": undefined;
8
- "function": Function;
9
- "object": object;
10
- "symbol": symbol;
11
- };
12
- declare type PrimitiveTypeStrings = keyof PrimitiveTypes;
13
- declare type NullableKeys<T> = {
14
- [K in keyof T]-?: undefined extends T[K] ? K : null extends T[K] ? K : never;
15
- }[keyof T];
16
- declare type PropsNonNullable<T, N extends NullableKeys<T>> = T & {
17
- [K in N]-?: NonNullable<T[K]>;
18
- };
19
- declare type Constructor<T> = new (...args: any[]) => T;
20
- declare type AllJSTypes = PrimitiveTypeStrings | null | undefined | Constructor<unknown>;
21
- declare type ResolveAnyJSType<T extends AllJSTypes> = T extends PrimitiveTypeStrings ? PrimitiveTypes[T] : T extends null ? null : T extends undefined ? undefined : T extends Constructor<infer U> ? U : never;
1
+ import type { UnknownFunction, Constructor, PrimitiveTypes, PrimitiveTypeStrings, NullableKeys, PropsNonNullable, AllJSTypes, ResolveAnyJSType, ResolveTuple, ResolveReadonlyTuple, Tuple, ReadonlyTuple } from "./types";
2
+ export type { PrimitiveTypes, PrimitiveTypeStrings, NullableKeys, PropsNonNullable, AllJSTypes, ResolveAnyJSType, ResolveTuple, ResolveReadonlyTuple, Tuple, ReadonlyTuple };
3
+ /**
4
+ * Error thrown by all assertie assertions when they fail.
5
+ */
6
+ export declare class AssertieError extends Error {
7
+ constructor(msg: string);
8
+ }
22
9
  /**
23
10
  * Asserts that the provided boolean is true.
24
11
  * @param {boolean} hasToBeTrue - The boolean to assert.
25
12
  * @param {string} msg - The message of the Error if the assertion fails.
26
- * @throws {AssertionError} if the assertion fails.
13
+ * @throws {AssertieError} if the assertion fails.
27
14
  */
28
15
  export declare function assert(hasToBeTrue: boolean, msg?: string): asserts hasToBeTrue is true;
29
16
  /**
30
- * Asserts that the provided object is of the expectedType.
31
- * @param {unknown} item - The object which ought to be of the expectedType.
32
- * @param {AllJSTypes} expectedType - The expected type of the object. JS primitive types, null, undefined, and constructable types are supported. JS primitive types are passed as the string they return from typeof, e.g., "number".
33
- * @throws {AssertionError} if the type isn't as expected.
17
+ * Asserts that the provided item is of the expectedType.
18
+ * @param {unknown} item - The item which ought to be of the expectedType.
19
+ * @param {AllJSTypes} expectedType - The expected type of the item. JS primitive types, null, undefined, and constructable types are supported. JS primitive types are passed as the string they return from typeof, e.g., "number".
20
+ * @throws {AssertieError} if the type isn't as expected.
34
21
  */
35
22
  export declare function assertType<T extends AllJSTypes>(item: unknown, expectedType: T): asserts item is ResolveAnyJSType<T>;
36
23
  /**
37
- * Asserts that all elements of the provided array are of the expected type. It ensures that the array is not sparse (even when the expectedType is undefined).
38
- * @param {unknown[]} arr - The array which ought to be an array of the expectedType, i.e. expectedType: "number" => arr: number[]
24
+ * Asserts that all elements of the provided array are of the expected type. It ensures that the array is not sparse up to arr.length (even when the expectedType is undefined).
25
+ * @param {unknown[]} arr - The array which ought to be an array of the expectedType, i.e. expectedType: "number" means `arr: number[]`. Preserves readonly when specified.
39
26
  * @param {AllJSTypes} expectedType - The expected type of individual items. JS primitive types, null, undefined, and constructable types are supported.
40
- * @throws {AssertionError} if the type isn't as expected.
27
+ * @throws {AssertieError} if the type isn't as expected.
41
28
  */
42
29
  export declare function assertArrayType<T extends AllJSTypes>(arr: unknown[], expectedType: T): asserts arr is ResolveAnyJSType<T>[];
30
+ export declare function assertArrayType<T extends AllJSTypes>(arr: readonly unknown[], expectedType: T): asserts arr is readonly ResolveAnyJSType<T>[];
43
31
  /**
44
32
  * Asserts that the array or tuple has the expected types at each index.
45
- * @param {unknown[] | [unknown, ...]} arrayOrTuple - The tuple which ought to be an array of the length and types.
46
- * @param {[AllJSTypes, ...]} expectedTypes - A tuple of expected types of individual items, e.g., expectedTypes = ["number", "string", Date] => arrayOrTuple: [number, string, Date]. The individual entries can be JS primitive types, null, undefined, and constructors.
47
- * @throws {AssertionError} if the type of any element of the tuple isn't as expected.
33
+ * @param {unknown[] | [unknown, ...]} arrayOrTuple - The tuple which ought to be an array of the expected length and types. Preserves readonly when specified.
34
+ * @param {[AllJSTypes, ...]} expectedTypes - A tuple of expected types of individual items, e.g., `expectedTypes = ["number", "string", Date]` means `arrayOrTuple: [number, string, Date]`. The individual entries can be JS primitive types, null, undefined, and constructors.
35
+ * @throws {AssertieError} if the type of any element of the tuple isn't as expected.
48
36
  */
49
37
  export declare function assertTupleTypes<T extends readonly AllJSTypes[], U extends {
50
38
  [K in keyof T]: unknown;
51
- } | (number extends U["length"] ? unknown[] : never)>(arrayOrTuple: U, expectedTypes: readonly [...T]): asserts arrayOrTuple is U & {
52
- [K in keyof T]: ResolveAnyJSType<T[K]>;
53
- };
39
+ } | (number extends U["length"] ? unknown[] : never)>(arrayOrTuple: U, expectedTypes: readonly [...T]): asserts arrayOrTuple is ResolveTuple<T, U>;
40
+ export declare function assertTupleTypes<T extends readonly AllJSTypes[], U extends {
41
+ readonly [K in keyof T]: unknown;
42
+ } | (number extends U["length"] ? readonly unknown[] : never)>(arrayOrTuple: U, expectedTypes: readonly [...T]): asserts arrayOrTuple is ResolveReadonlyTuple<T, U>;
54
43
  /**
55
44
  * Asserts that the provided item is of type string.
56
45
  * @param {unknown} item - The item which ought to be of type string.
57
- * @throws {AssertionError} if the type isn't string.
46
+ * @throws {AssertieError} if the type isn't string.
58
47
  */
59
48
  export declare function assertTypeOfString(item: unknown): asserts item is string;
60
49
  /**
61
50
  * Asserts that the provided item is of type number.
62
51
  * @param {unknown} item - The item which ought to be of type number.
63
- * @throws {AssertionError} if the type isn't number.
52
+ * @throws {AssertieError} if the type isn't number.
64
53
  */
65
54
  export declare function assertTypeOfNumber(item: unknown): asserts item is number;
66
55
  /**
67
56
  * Asserts that the provided item is of type boolean.
68
57
  * @param {unknown} item - The item which ought to be of type boolean.
69
- * @throws {AssertionError} if the type isn't boolean.
58
+ * @throws {AssertieError} if the type isn't boolean.
70
59
  */
71
60
  export declare function assertTypeOfBoolean(item: unknown): asserts item is boolean;
72
61
  /**
73
62
  * Asserts that the provided item is of type bigint.
74
63
  * @param {unknown} item - The item which ought to be of type bigint.
75
- * @throws {AssertionError} if the type isn't bigint.
64
+ * @throws {AssertieError} if the type isn't bigint.
76
65
  */
77
66
  export declare function assertTypeOfBigint(item: unknown): asserts item is bigint;
78
67
  /**
79
68
  * Asserts that the provided item is of type undefined.
80
69
  * @param {unknown} item - The item which ought to be of type undefined.
81
- * @throws {AssertionError} if the type isn't undefined.
70
+ * @throws {AssertieError} if the type isn't undefined.
82
71
  */
83
72
  export declare function assertTypeOfUndefined(item: unknown): asserts item is undefined;
84
73
  /**
85
74
  * Asserts that the provided item is of type function.
86
75
  * @param {unknown} item - The item which ought to be of type function.
87
- * @throws {AssertionError} if the type isn't function.
76
+ * @throws {AssertieError} if the type isn't function.
88
77
  */
89
- export declare function assertTypeOfFunction(item: unknown): asserts item is Function;
78
+ export declare function assertTypeOfFunction(item: unknown): asserts item is UnknownFunction;
90
79
  /**
91
80
  * Asserts that the provided item is of type object.
92
81
  * @param {unknown} item - The item which ought to be of type object.
93
- * @throws {AssertionError} if the type isn't object.
82
+ * @throws {AssertieError} if the type isn't object.
94
83
  */
95
84
  export declare function assertTypeOfObject(item: unknown): asserts item is object;
96
85
  /**
97
86
  * Asserts that the provided item is of type symbol.
98
87
  * @param {unknown} item - The item which ought to be of type symbol.
99
- * @throws {AssertionError} if the type isn't symbol.
88
+ * @throws {AssertieError} if the type isn't symbol.
100
89
  */
101
90
  export declare function assertTypeOfSymbol(item: unknown): asserts item is symbol;
102
91
  /**
103
92
  * Asserts that the provided item is null.
104
93
  * @param {unknown} item - The item which ought to be null.
105
- * @throws {AssertionError} if the value isn't null.
94
+ * @throws {AssertieError} if the value isn't null.
106
95
  */
107
96
  export declare function assertNull(item: unknown): asserts item is null;
108
97
  /**
109
98
  * Asserts that the provided item is an instance of the provided constructor.
110
99
  * @param {unknown} item - The item which ought to be an instance of the constructor.
111
100
  * @param {Constructor<T>} constructor - Anything that can be after an instanceof operator.
112
- * @throws {AssertionError} if item instanceof constructor is false.
101
+ * @throws {AssertieError} if item instanceof constructor is false.
113
102
  */
114
103
  export declare function assertInstanceOf<T>(item: unknown, constructor: Constructor<T>): asserts item is T;
115
104
  /**
116
105
  * Asserts that the provided array is a tuple of exactly the expected length.
117
106
  * @param {unknown[]} arr - The array which ought to be a tuple.
118
107
  * @param {number} expectedLength - The exact expected length of the tuple.
119
- * @throws {AssertionError} if the array isn't of the expected length or is sparse.
108
+ * @throws {AssertieError} if the array isn't of the expected length or is sparse.
120
109
  */
121
- export declare function assertIsTuple<T extends number extends T["length"] ? unknown[] : never, N extends number>(arr: [...T], expectedLength: N): asserts arr is T & Tuple<T[number], N>;
110
+ export declare function assertIsTuple<T, N extends number>(arr: T[], expectedLength: N): asserts arr is Tuple<T, N>;
111
+ export declare function assertIsTuple<T, N extends number>(arr: readonly T[], expectedLength: N): asserts arr is ReadonlyTuple<T, N>;
122
112
  /**
123
113
  * Used to assert that code can never be reached. Pass a value which has already been checked for all types that should be possible. If the range of possible values increases, TypeScript will throw an error at compile time because the value won't be of type never.
124
114
  * @param {never} item - An exhausted value, of which all cases are accounted for in other branches of the code, such as at the end of a switch statement.
125
115
  * @param {string} msg - Override the default error message. Even if you do, the error message will include the value and type of item.
126
- * @throws {AssertionError} if at runtime the function call was reached. This should only happen if TypeScript types are inaccurate somewhere.
116
+ * @throws {AssertieError} if at runtime the function call was reached. This should only happen if TypeScript types are inaccurate somewhere.
127
117
  */
128
118
  export declare function assertUnreachable(item: never, msg?: string): asserts item is never;
129
119
  /**
130
120
  * Asserts that the provided item is neither null nor undefined.
131
121
  * @param {unknown} item - The item which ought to be non-null.
132
- * @throws {AssertionError} if the item is null or undefined.
122
+ * @throws {AssertieError} if the item is null or undefined.
133
123
  */
134
124
  export declare function assertNonNullable<T>(item: T): asserts item is NonNullable<T>;
135
125
  /**
136
126
  * Asserts that the provided object has non-null values for the properties passed as keys in the propKeys array.
137
127
  * @param {object} obj - The object which ought to have the properties.
138
128
  * @param {NullableKeys<T>} propKeys - An array of the stringified keys of the properties which ought to be non-null in the object.
139
- * @throws {AssertionError} if any of the properties was null, undefined, or not present in the object.
129
+ * @throws {AssertieError} if any of the properties was null, undefined, or not present in the object.
140
130
  */
141
131
  export declare function assertPropsNonNullable<T extends object, N extends NullableKeys<T>>(obj: T, propKeys: N[]): asserts obj is PropsNonNullable<T, N>;
142
132
  /**
143
133
  * Asserts that all elements of the provided array are neither null nor undefined, or not present.
144
- * @param {unknown[]} arr - The array which ought to be non-sparse, and have only non-null elements.
145
- * @throws {AssertionError} if any of the elements was null, undefined, or not present in the array.
134
+ * @param {unknown[]} arr - The array which ought to be non-sparse, and have only non-null elements. Preserves readonly when specified.
135
+ * @throws {AssertieError} if any of the elements was null, undefined, or not present in the array.
146
136
  */
147
137
  export declare function assertArrayNonNullable<T>(arr: T[]): asserts arr is NonNullable<T>[];
138
+ export declare function assertArrayNonNullable<T>(arr: readonly T[]): asserts arr is readonly NonNullable<T>[];
148
139
  /**
149
140
  * Asserts that the provided tuple has non-null values for all elements. This function does not take a length. So if you want to assert that the typescript tuple type is of the correct length, call @see assertIsTuple first.
150
141
  * @param {[unknown, ...]} tuple - The tuple which ought to have only non-null values.
151
- * @throws {AssertionError} if any of the elements was null, undefined, or an index not present in the tuple.
142
+ * @throws {AssertieError} if any of the elements was null, undefined, or an index not present in the tuple.
152
143
  */
153
144
  export declare function assertTupleNonNullable<T extends number extends T["length"] ? never : unknown[]>(tuple: T): asserts tuple is {
154
145
  [K in keyof T]: NonNullable<T[K]>;
155
146
  };
147
+ export declare function assertTupleNonNullable<T extends number extends T["length"] ? never : readonly unknown[]>(tuple: T): asserts tuple is {
148
+ [K in keyof T]: NonNullable<T[K]>;
149
+ };
156
150
  /**
157
151
  * Asserts that the provided item is a finite number. Use to prevent NaN propagation.
158
152
  * @param {unknown} item - The item which ought to be a finite number.
159
- * @throws {AssertionError} if the item is not of type number, or isFinite(item) is false, i.e., if the item is NaN, Infinity, or -Infinity.
153
+ * @throws {AssertieError} if the item is not of type number, or isFinite(item) is false, i.e., if the item is NaN, Infinity, or -Infinity.
160
154
  */
161
155
  export declare function assertFiniteNumber(item: unknown): asserts item is number;
162
- export {};