【发布时间】:2018-03-09 09:07:50
【问题描述】:
我有这个打字稿代码 (typescript playground):
const enum Something {
None = 0,
Email = 10,
All = 20
}
const enum Other{
Email = 10;
Value = 15;
}
interface Foo {
prop: Something
}
const value2: Something = Something.None;
// Why can 15 be assigned if it's not in the enum?
const value: Something = 15;
// This errors:
const otherValue: Something = 'asdf';
const value3: Something = Something.NotExists;
const value4: Something = Other.Value;
const value5: Something = Other.Email;
我不明白为什么在这种情况下 15 是一个可接受的值。 15 不是枚举的值,所以不应该抛出吗?
【问题讨论】:
-
我相信这里已经回答了这个问题:stackoverflow.com/questions/25762823/…
标签: typescript enums