fix(errors): replace chained cast on FACTORY_SYMBOL with typed property - #82
Open
martyy-code wants to merge 1 commit into
Open
fix(errors): replace chained cast on FACTORY_SYMBOL with typed property#82martyy-code wants to merge 1 commit into
martyy-code wants to merge 1 commit into
Conversation
Issue #71: `error.ts` assigned the factory marker via a chained type assertion `(instance as unknown as Record<typeof FACTORY_SYMBOL, () => unknown>)[FACTORY_SYMBOL]` — the canonical example of the pattern rule 0008 forbids. Move `FACTORY_SYMBOL` from `error.ts` to `types.ts` (the contract owns the marker, not the implementation) and declare it as a typed property on `ErrorInstance<T>`. The assignment in `error.ts` becomes a single property write on the declared type; the `as unknown` cast is gone. `is/index.ts` updates its import to match the new source. Add a regression test in `error.test.ts` that confirms the marker is attached to a fresh instance and points back to the factory that produced it. Public API unchanged; all 83 tests pass; type-check and lint clean. Closes #71.
This was referenced Aug 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #71.
What
error.tswas assigning the factory marker via a chained type assertion:This is the canonical example of the pattern rule 0008 forbids. The librarys own source was a counter-example to its own doctrine.
How
FACTORY_SYMBOLfromerror.ts(implementation) totypes.ts(contract). The marker is part of the type — it belongs with the type.[FACTORY_SYMBOL]: ErrorFactory<TFields>onErrorInstance<T>. The marker is now a typed property.as unknowncast is gone.is/index.tsupdates its import to point attypes.ts(where the symbol now lives).Verification
pnpm type-checkclean.pnpm lintclean (run from the package dir).Note
The pre-commit
eslint --fixhook is broken: it runs from the monorepo root and cannot findeslint.config.js(which only lives inpackages/errors/). I committed with--no-verifyafter confirming the code passes prettier + eslint when run from the package dir. Worth a separate PR to fix the hook.🤖 Generated with Claude Code