typescript enhanced: better Intelligent perception and TS checks #2054
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.
Better intelligent prompt and TS checks and without affecting functions already supported by TS.
state
,getters
infinite hierarchical property hints, and support read-only checks.commit
,dispatch
methods sense all operational type names and check payload parameters.Unsupported actions:
(store.dispatch as any) ('doSomething')
way to skip detection,Incompatible usage methods:
createStore<State>({...})
The type specified through generics cannot be supported because all configuration items need to be passed!
Instead of manually specifying
<State>
, the default will automatically infer from the state option; When you need a custom type, useclass
to define and set the initial value, and then create an instance in the state configuration item;const key: InjectionKey<Store<State>> = Symbol()
The current store type needs to use the
<typeof store >
wayglobal type supplement
更好的提供感知提示及TS校验,在不影响已有TS支持的功能情况下, 增强 state, getters 无限层级属性提示,并支持只读校验; 增强 commit、dispatch 方法感知所有操作类型名称并对载荷参数校验,类型名称支持namespaced配置进行拼接。
不支持的操作:
1、不支持对象方式分发或提交,因为没有限制载荷必须为对象类型
2、不支持在带命名空间的模块注册全局 action,不推荐这种用法
3、不支持动态注册的模块, 需要使用
(store.dispatch as any)('doSomething')
的方式来跳过检测