fix(kida): type toAccessor by what it actually returns - #208
Merged
Conversation
`ToAccessor` and `ToAccessorOrSignal` tested `AnyAccessor`, so a function that takes an argument fell through to the wrapping branch: `toAccessor(event => …)` was typed `Accessor<(event) => …>` while it returned the callback itself, and `toAccessorOrSignal` claimed a `WritableSignal` of it. The test behind both is `isAccessor`, which is `typeof value === 'function'`. It cannot tell a callback from an accessor and hands either one back untouched, so the types now test `AnyFn` and say the same.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #208 +/- ##
=======================================
Coverage 85.33% 85.33%
=======================================
Files 139 139
Lines 3143 3143
Branches 591 591
=======================================
Hits 2682 2682
Misses 332 332
Partials 129 129 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
toAccessorandtoAccessorOrSignaldecide what to do with atypeoftest:isAccessoristypeof value === 'function'. It cannot tell an accessor from a callback, and it does not try — either one is handed back untouched.The types said otherwise. They tested
AnyAccessor, which isAccessor<any>— a zero-argument function. A callback takes an argument, so it is not assignable, so it fell through to the wrapping branch:toAccessorOrSignalwas wrong the same way, and worse — it claimed aWritableSignalof the callback.Both now test
AnyFn, which is what the runtime tests:Nothing else changes. A plain value still becomes
Accessor<T>, an accessor or a signal still comes back as itself; only the case that was already lying is corrected.Types only — every bundle in the chain is byte-identical, and no size pin moves. Checked across all eleven packages: lint,
tsc --noEmitand the unit suites are green.This matters beyond the two functions:
nanoviews'props$reads props in accessor form with the sametypeofrule, and it types its result withToAccessor. Before this fix, a callback prop taken as$onSelectwould have been typed as an accessor wrapping the callback rather than as the callback itself.