77 catch blocks in non-test source do (err as Error).message (101 counting tests). If a non-Error is thrown, the message is undefined and the user sees an empty error.
// packages/web/src/stores/authStore.ts -- 10 occurrences in this file alone
catch (err) { set({ authError: (err as Error).message }); }
useUnknownInCatchVariables is already on via strict, so err is correctly unknown -- the cast is throwing that away.
Fix
One helper in @corates/shared:
export function errorMessage(e: unknown): string {
return e instanceof Error ? e.message : String(e);
}
Name it to avoid getErrorMessage(code: string), which already exists in packages/shared/src/errors/helpers.ts and maps an error code to its default message. Then convert the call sites. Note that several files already do this correctly inline (err instanceof Error ? err.message : String(err) appears in the guards), so the helper also de-duplicates that.
Done when
- Helper exists in
@corates/shared
- No
as Error in non-test source (currently 77)
Effort: 2-3 hours, mechanical.
Carried over from packages/docs/audits/typescript-audit-2026-04.md item 9, which measured ~100 in April counting tests. It is 101 now on the same basis, 77 in non-test source.
Part of #778 (TypeScript correctness target state and tracker).
77 catch blocks in non-test source do
(err as Error).message(101 counting tests). If a non-Error is thrown, the message isundefinedand the user sees an empty error.useUnknownInCatchVariablesis already on viastrict, soerris correctlyunknown-- the cast is throwing that away.Fix
One helper in
@corates/shared:Name it to avoid
getErrorMessage(code: string), which already exists inpackages/shared/src/errors/helpers.tsand maps an error code to its default message. Then convert the call sites. Note that several files already do this correctly inline (err instanceof Error ? err.message : String(err)appears in the guards), so the helper also de-duplicates that.Done when
@corates/sharedas Errorin non-test source (currently 77)Effort: 2-3 hours, mechanical.
Carried over from
packages/docs/audits/typescript-audit-2026-04.mditem 9, which measured ~100 in April counting tests. It is 101 now on the same basis, 77 in non-test source.Part of #778 (TypeScript correctness target state and tracker).