【发布时间】:2015-12-23 16:17:07
【问题描述】:
以下内容编译时不会出现错误“声明类型既不是 void 也不是任何必须返回值或由单个 throw 语句组成的函数”。
有没有办法让编译器识别 _notImplemented 抛出异常?
function _notImplemented() {
throw new Error('not implemented');
}
class Foo {
bar() : boolean { _notImplemented(); }
我能看到的唯一解决方法是使用泛型。但这似乎有点hacky。有没有更好的办法?
function _notImplemented<T>() : T {
throw new Error('not implemented');
}
class Foo {
bar() : boolean { return _notImplemented(); }
【问题讨论】:
标签: typescript1.7