0
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?

【React初心者メモ】エイリアス(:)

Last updated at Posted at 2025-06-07

エイリアスとは

エイリアスとは、変数名やプロパティ名を他の名前で扱う構文です。

使われる場面

1.オブジェクトの分割代入でエイリアスを使う

const user = {
  id: 1,
  username: 'hana',
  age: 20
};
// username → name に別名をつけて使う
const { username: name } = user;
console.log(name); // 'hana'

2.関数の引数でエイリアスを使う

const printUser = ({ username: name }: { username: string }) => {
  console.log(name);
};
printUser({ username: 'taro' }); // 'taro'

3.型でエイリアスを使う

type UserId = number;
const getUser = (id: UserId): void => {
  console.log("ID:", id);
};
0
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
0
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?