YanoRyuichi.com/
Wiki
Blog
GitHub
Sandbox
開始行:
* enum [#r1f46ff1]
*** price.enum.ts [#o0c01a86]
export enum Price {
book = 500,
pen = 120,
eraser = 80
}
*** index.ts [#keba55cf]
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')); // エラー
終了行:
* enum [#r1f46ff1]
*** price.enum.ts [#o0c01a86]
export enum Price {
book = 500,
pen = 120,
eraser = 80
}
*** index.ts [#keba55cf]
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')); // エラー
ページ名: