最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Why can TypeScript generics be recursive within a class generic-extends-guard? - Stack Overflow

programmeradmin1浏览0评论

I was writing some code and trying to figure out how to ensure that the generic type passed into a class satisfies "string keys to function records", and the only thing that would work and wouldn't cause tsc to complain was this:

type EventMap<T> = { [K in keyof T]: (...args: any) => any }

export class wRPC<In extends EventMap<In>, Out extends EventMap<Out>> {
//...

Why does this work? Whether it's in an extracted type or inlined, TypeScript lets me reference In within the extends guard that it satisfies. How is this allowed?

发布评论

评论列表(0)

  1. 暂无评论