2
1

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 1 year has passed since last update.

interface使用例 (composition api)

Last updated at Posted at 2022-06-02

使用例

<script setup lang="ts">

enum Gender {
  GIRL = "Girl",
  BOY = "Boy",
}

enum Hobby {
  SPORT = "Sport",
  TVGAME = "TvGame",
}

enum Score {
  HIGH = "High",
  MIDDLE = "Middle",
  LOW = "Low",
}

interface Human {
  gender: Gender;
  hobby: Hobby;
  score: Score;
}

const options = reactive<Human>({
  gender: Gender.GIRL,
  hobby: Hobby.SPORT,
  score: Score.HIGH,
});
</script>

このようにinterfaceとenumを合わせて使用すれば、
指定した値以外の混入を防げる。

例えば、

const options = reactive<Human>({
  gender: 'girl',
  hobby: Hobby.SPORT,
  score: Score.HIGH,
});

のように書くことができない

2
1
1

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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?