LoginSignup
1
1

More than 1 year has passed since last update.

【TypeScript】型定義用のファイルを作成して型定義

Posted at

プログラミング勉強日記

2022/05/18
TypeScript の型定義時、ファイルを分けて定義する方法を知ったのでまとめる。

型(タイプ)定義専用のファイルを用意して記述する

src 配下にtypesフォルダを作成
types配下にUserProfile.tsを作成
UserProfile.tsに以下を記述

types/UserProfile.ts
export type UserProfile = () => {
  id: number;
  name: string;
  mail: string;
  address: string;
};

あとは、使いたいファイルでimport して使用する。
型定義しておくと、下記画像のようにエディタの保管機能でタイポを失くせるので便利。

スクリーンショット 2022-05-18 21.47.12.png

1
1
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
1
1