9cubed
ブログ | Tailwind | Vite | Python | Node.js | Linux | PowerShell | その他 | 将棋ウォーズ | 歌の練習
< 前の記事

TypeScript - 配列

次の記事 >

TypeScript - タプル型

TypeScript

TypeScript - 列挙型(enum)

公開日:2019-01-15
更新日:2019-05-14

1. 概要

列挙型(enum)の使い方です。

enum 型名 {要素, 要素, 要素, ... }

2.1 サンプル

enum OnOff { ON, OFF }

let sw: OnOff = OnOff.ON;

sw = OnOff.OFF;

//なぜか数値を設定してもエラーにならない
sw = 123;

2.2 サンプル

enum Direction {
	Up    = 1,
	Down  = 2,
	Left  = 3,
	Right = 4
}

let d: Direction = Direction.Up;

if (d == Direction.Up) console.log('Up');

if (d == Direction.Up.valueOf())   console.log('Up');
if (d == Direction.Down.valueOf()) console.log('Down');

if (d == 1) console.log('Up');
if (d == 2) console.log('Down');

console.log(d); //1

Up
Up
Up
1


< 前の記事

TypeScript - 配列

次の記事 >

TypeScript - タプル型

YouTube X

新着一覧

  • SCSS のインストールVite
  • Tailwind CSS のプロジェクトの作成Tailwind
  • TypeScriptのプロジェクトの作成Vite
  • Flask のインストールと動作確認Python
  • 簡易Webサーバーの作成Python
  • pipeline で文章の生成Python
  • pipeline で文章の要約Python
  • 音声から文字起こしPython
  • Node.js のインストールNode.js
  • .ps1(PowerShellスクリプト)を実行可能にするPowerShell

アーカイブ

  • 2025/12
  • 2025/11
  • 2025/10
  • 2025/09
  • 2025/08

以前のカテゴリー一覧

  • CakePHP3
  • CentOS7
  • HTML・CSS・JavaScript
  • Haskell
  • JavaScript
  • Kotlin
  • Laravel5
  • PHP
  • Python
  • Ruby
  • RubyOnRails5
  • TypeScript
  • Vue.js
  • Webサーバ講座
  • Webプログラミング講座
  • jQuery
  • linux
  • パソコン講座
  • ブログ
  • プログラミング講座
  • メモ帳作成講座
  • 数学

Copyright © 9cubed. All Rights Reserved.

プライバシーポリシー 利用規約
▲