TS函数重载类型推断

当从函数重载推断类型时,只会从最后一个函数签名中推断,比如:

typescript
interface EventBus {
  (
event
: 'refresh',
type
: string):void;
(
event
: 'query',
data
: number):void;
} type
Inferred
=
Parameters
<EventBus> extends [infer
K
, ...infer
U
] ?
U
: never;
// type Inferred === [number]

当从多个调用签名中推断类型时(比如函数重载类型),总是会从最后一个签名中推断(因为是最有可能包含所有情况的签名)。这里没有办法展示出重载的参数类型数组。

When inferring from a type with multiple call signatures (such as the type of an overloaded function), inferences are made from the last signature (which, presumably, is the most permissive catch-all case). It is not possible to perform overload resolution based on a list of argument types.

85bd - feat: add twoslash for some posts
4c95 - chore: organize directory structure
8d21 - docs: migrate front-end posts
6fc9 - wip: global Code Preview component
fdc7 - chore: rename `src` to `content`
18e0 - wip: custom vitepress theme
7fa1 - feat: add blog
7b86 - wip(list): collections
971e - feat: add blog & stereotyped-writing
评论加载中 (ง •̀ω•́)ง