hooks
hooks copied to clipboard
fix(types): use T as previous state type
🤔 This is a ...
- [ ] New feature
- [ ] Bug fix
- [ ] Site / documentation update
- [ ] Demo update
- [x] TypeScript definition update
- [ ] Bundle size optimization
- [ ] Performance optimization
- [ ] Enhancement feature
- [ ] Internationalization
- [ ] Refactoring
- [ ] Code style optimization
- [ ] Test Case
- [ ] Branch merge
- [ ] Other (about what?)
🔗 Related issue link
https://github.com/alibaba/hooks/pull/1630
💡 Background and solution
Before:
const [name, setName] = useLocalStorageState<string>('name', { defaultValue: '' });
setName((n) => n.slice(1));
// (parameter) n: string | undefined
// 检测到无法访问的代码。ts(7027)
// 对象可能为“未定义”。ts(2532)
📝 Changelog
| Language | Changelog |
|---|---|
| 🇺🇸 English | |
| 🇨🇳 Chinese |
☑️ Self Check before Merge
⚠️ Please check all items below before review. ⚠️
- [x] Doc is updated/provided or not needed
- [x] Demo is updated/provided or not needed
- [x] TypeScript definition is updated/provided or not needed
- [ ] Changelog is provided or not needed
same: https://github.com/alibaba/hooks/pull/2148, and #2148 is better