7
3

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 3 years have passed since last update.

【TypeScript入門】呼び出しシグネチャとは

Posted at

まとめ

呼び出しシグネチャを使うことでアノテーションをたくさん書く必要がなくなります。また、再利用ができるのでコードの質も高まります。

呼び出しシグネチャとは

  • どのような関数なのかを表現する型定義
  • 省略記法はアロー関数と似た形
  • 安全な記法はオブジェクトと似た形
省略版
type LogMessage = (message: string) => void
export const logMessage: LogMessage = (message) => {
  console.log('sample:', message)
}
完全版
type FullLogMessage = {
  (message: string): void
}
export const logMessage: FullLogMessage = (message) => {
  console.log('sample:', message)
}
7
3
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
7
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?