ErrorMessage: accept unknown in constructor

This commit is contained in:
Elijah Duffy
2026-04-21 18:08:57 -07:00
parent 52cd3c6e8d
commit d1019659f5

View File

@@ -78,7 +78,7 @@ export class ErrorMessage {
* @param errors The raw errors to convert and store, or null/undefined for no error. * @param errors The raw errors to convert and store, or null/undefined for no error.
* @throws If any of the raw errors are of an unsupported type. * @throws If any of the raw errors are of an unsupported type.
*/ */
constructor(...errors: (RawError | null | undefined)[]) { constructor(...errors: (unknown | null | undefined)[]) {
if (errors.length === 0) return; if (errors.length === 0) return;
this._lines = errors.flatMap((e) => ErrorMessage.rawErrorToLines(e)); this._lines = errors.flatMap((e) => ErrorMessage.rawErrorToLines(e));
} }
@@ -87,7 +87,7 @@ export class ErrorMessage {
* Creates a new ErrorMessage only if the provided errors are not null or * Creates a new ErrorMessage only if the provided errors are not null or
* undefined. If no errors are provided, returns null. * undefined. If no errors are provided, returns null.
*/ */
static from(...errors: (RawError | null | undefined)[]): ErrorMessage | null { static from(...errors: (unknown | null | undefined)[]): ErrorMessage | null {
if (errors.length === 0) return null; if (errors.length === 0) return null;
return new ErrorMessage(...errors); return new ErrorMessage(...errors);
} }
@@ -97,7 +97,7 @@ export class ErrorMessage {
* @param errors The raw errors to wrap around this error, or null/undefined for no additional error. * @param errors The raw errors to wrap around this error, or null/undefined for no additional error.
* @returns A new ErrorMessage instance that includes the original error and any new errors. * @returns A new ErrorMessage instance that includes the original error and any new errors.
*/ */
wrap(...errors: (RawError | null | undefined)[]): ErrorMessage { wrap(...errors: (unknown | null | undefined)[]): ErrorMessage {
if (errors.length === 0) return this; if (errors.length === 0) return this;
const newLines = errors.flatMap((e) => ErrorMessage.rawErrorToLines(e)); const newLines = errors.flatMap((e) => ErrorMessage.rawErrorToLines(e));
return new ErrorMessage(...newLines, ...this._lines); return new ErrorMessage(...newLines, ...this._lines);
@@ -122,7 +122,7 @@ export class ErrorMessage {
} }
/** converts a RawError to an array of lines */ /** converts a RawError to an array of lines */
static rawErrorToLines(raw: RawError | null | undefined): string[] { static rawErrorToLines(raw: unknown | null | undefined): string[] {
if (!raw) return []; if (!raw) return [];
let errorLines: string[]; let errorLines: string[];