如何利用 Typescript 的类型编程自动推断 Redux reducer 的类型
今日,使用 ts 几乎已经变成前端的政治正确了。虽然 ts 的自动类型推导已经很强大了,但受限于 js 语言本身,我们依然需要手写很多的类型,并且手动的去指定。比如说在使用 ts 编写 redux 的 reducer 时,我们该怎样保证 action 类型的正确性呢?简单,但不正确最简单的,我们可以这么写type Action = { type: string; payload: unknown;}function reducer(state: {}, action: Action)
原创
2020-08-15 20:50:55 ·
1539 阅读 ·
0 评论