microsoft / microsoft/TypeScript
Reusing function type with different parameters amount (overloading)
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
Bug Report
Is there any reason it's not possible to re-use a function type that is overloaded aka has different possible amount of arguments?
In the playground I put some code that shows this issue, but I will put a quick snippet here:
declare function foo(c: {a: number; b: string}): void
declare function foo(a: number, b: string): void
foo({ a: 1, b: "2" })
foo(1, "2")
// This doesn't work but is relatively understandable
const bar1: typeof foo = (a_c, b) => {
a_c
b
}
// This should work, why it doesn't?
const bar2: typeof foo = (...args) => {
args
}
// it works fine, but you can't access the second parameter
const bar3: typeof foo = (a_c) => {
a_c
}
// it works fine, but you can't access the parameters
const bar4: typeof foo = () => {
}
bar2 in this example doesn't work, and the error that is given is Type '(args_0: number | { a: number; b: string; }, args_1: unknown) => void' is not assignable to type '{ (c: { a: number; b: string; }): void; (a: number, b: string): void; }'.
🔎 Search Terms
arguments overload parameter function
🕗 Version & Regression Information
In 4.4.0-beta & 4.3.5:

In 4.2.3 and before:

⏯ Playground Link
🙁 Actual behavior
It just errors out when trying to use "...args" to get all the possible arguments of the function
🙂 Expected behavior
To be able to use "...args" or similar to get the arguments and typescript to not complain just for trying to use it
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、報告されているバージョン 4.3.5 と 4.4.0-beta を使って、リンク先の TypeScript Playground でオーバーロードの代入動作を再現します。受け入れられる例と拒否される例を比較し、その後、オーバーロードされた関数の rest パラメーター実装に対して意図される動作を判断します。動作と期待される型付けが確立され、適切な compiler test でカバーされれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 25/100