hooks icon indicating copy to clipboard operation
hooks copied to clipboard

fix(types): use T as previous state type

Open CHOYSEN opened this issue 3 years ago • 1 comments

[中文版模板 / Chinese template]

🤔 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

CHOYSEN avatar Jul 01 '22 08:07 CHOYSEN

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Jul 01 '22 08:07 CLAassistant

same: https://github.com/alibaba/hooks/pull/2148, and #2148 is better

liuyib avatar Jul 05 '23 13:07 liuyib