tusbasaのブログ

業務や勉強中に調べたことを自分用にメモするブログ

【Typescript】ReturnType、typeofの組み合わせで型定義

ReturnType、typeofの組み合わせで関数の戻り値を型として扱う書き方ができる

const useNumber = () => {
  return {
    a: 'xxxx',
    ....
  }
}

const data = useNumber()

type useNumerType = ReturnType<typeof useNumber>


# 引数のdataに型定義ができる
const processing = (data: useNumerType) => {
....
}

参考

asukiaaa.blogspot.com