2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

インターフェースで関数のオーバーロードを記述する

Posted at

はじめに

最近、TypeScriptを使っていて覚えたことの共有です。

インターフェースで関数のオーバーロードを記述する

コールシグネチャを含んだインターフェースを定義すると、関数に対するインターフェースを作成できる。
これを応用すれば、関数のオーバーロード情報を持つインターフェースを定義できる。

// 関数のオーバーロード情報
interface ICallSignature {
	(a: string): any;
	(a: number): any;
}

// オーバーロードのある関数の実装
function f(a: string): any
function f(a: number): any
function f(a: string | number): any {
};

// 関数へのインターフェースの適用
const hoge: ICallSignature = f;

おわりに

また何かあったら投稿します。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?