2.0.0-rc setter draft/prev lies about type if the primitive hasn't gotten initialized with a value yet
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 36.1k
- Forks
- 1.1k
- Avg merge
- 9h 18m
- Merged PRs (30d)
- 195
Description
Describe the bug
If a derived signal/store/optimistic/optimisticStore has never been initialized when its setter is called the setter callback gets provided with a uninitialized prev/draft either undefined for the signal case or the seed value for the store case.
Your Example Website or App
https://stackblitz.com/edit/solidjs-templates-kkcngwa1?file=src%2FApp.tsx
Steps to Reproduce the Bug or Issue
- Open repro
- Click button
- See in console that each setter logged that they received a value that doesn't correspond to the type
Expected behavior
I honestly don't know. The alternatives are:
- Throw an error
- Update the type to reflect the reality for derived types
- Ignore the set never calling the callback
- Queue the set calling the callback once there is a value
This case should be reasonably rare but also not just hypothetical so the solution needs to way what is least bad here. Do we force everyone to handle a undefined even when the derived signal is sync and can't possibly be in this state or do we try to retain the type but introduce some possibly unintuitive behavior for what happens when it is called in this state?
My preferred solution is probably 4 however both 3 and 4 require changing the contract for the setter to no longer return the updated value as that obviously can't be done if the setter callback hasn't been called yet.
Screenshots or Videos
No response
Platform
- OS: Windows
- Browser: Firefox
Additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked StackBlitz reproduction and inspect the derived signal, store, optimistic, and optimisticStore setter callbacks. Compare the received prev/draft values with their declared types and trace the setter return contract. Done means one documented behavior is selected and the callback inputs and return values consistently implement it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100