Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

精读《Typescript 4.0》 #259

Closed
ascoders opened this issue Jul 12, 2020 · 6 comments
Closed

精读《Typescript 4.0》 #259

ascoders opened this issue Jul 12, 2020 · 6 comments

Comments

@ascoders
Copy link
Owner

ascoders commented Jul 12, 2020

Typescript 4 Beta 版来啦!,虽然是一个大版本,但从 3.9 升级到 4 不会遇到太大问题,让我们一起了解一下内容吧。


精读《Typescript 4.0》

@waitingsong
Copy link

不知道啥时能支持对类型名的转换,比如类型名追加字符串。

@ascoders
Copy link
Owner Author

@waitingsong 能举一个 case 吗

@crimx
Copy link

crimx commented Jul 13, 2020

@ascoders 笔记中 useDesigner 参数展开数组的用法在 TS3 就已经支持了,所以应该不算是 TS4 的例子。

取动态交集类型可以用 Conditional types 配合 Type inference in conditional types 的黑魔法。

type IntersectionFromUnion<TUnion> = (TUnion extends any
  ? (arg: TUnion) => void
  : never) extends (arg: infer TArg) => void
    ? TArg
    : never

const useDesigner = <T extends Array<(state?: any) => any>>(
  ...selectors: T
): IntersectionFromUnion<ReturnType<T[number]>> =>
  useSelector(state =>
    selectors.reduce((selected, selector) => {
      return {
        ...selected,
        ...selector(state)
      }
    }, {} as any)
  )

@waitingsong
Copy link

@waitingsong 能举一个 case 吗

microsoft/TypeScript#12754

@Gavin-Gong
Copy link

不知道啥时能支持对类型名的转换,比如类型名追加字符串。

有望在 4.1 版本实现

@waitingsong
Copy link

@Gavin-Gong 嗯,看到计划了
microsoft/TypeScript#40124

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants