enum

price.enum.ts

 export enum Price {
     book = 500,
     pen = 120,
     eraser = 80
 }

index.ts

 import { Price } from './price.enum';
 
 function totalPrice(arg1: Price, arg2: Price) {
     return arg1 + arg2;
 }
 
 console.log(totalPrice(Price.book, Price.pen)); // OK
 console.log(totalPrice(Price.book, 1));         // OK
 console.log(totalPrice(Price.book, 'abc'));     // エラー

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS

Last-modified: 2019-10-09 (水) 14:49:39