enumprice.enum.tsexport enum Price { book = 500, pen = 120, eraser = 80 } index.tsimport { 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')); // エラー |
|