-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't implement interface by throwing error #16874
Comments
These should be identical: const o1: I = { m: function () { throw new Error('nyi'); } }
const o2: I = { m() { throw new Error("not implemented"); } } |
@DanielRosenwasser Probably need more input from other people but I think it'd be better to have a flag that undoes #8767 rather than a mashup type of I'm actually fine with getting an error in this case: class Base {
overrideMe() {
throw new Error("You forgot to override me!");
}
}
class Derived extends Base {
overrideMe() {
// Code that actually returns here
}
} From my perspective, it's better to have to explicitly annotate the return type in the base class, because it might be the case that my to-be-overridden function is actually supposed to return string, or an array, or any number of other things, and an inferred return type of |
@masaeedu we talked about this quite a bit last week. The problem with erroring in the above code is that it would be a breaking change. The only reason we even did #8767 was because the number of breaks it induced was too significant. Breaking change concerns aside, the good thing with giving a type Re: another flag... this is not something that would be worth doubling the configuration space of TypeScript over. |
TypeScript Version: nightly (2.5.0-dev.20170629)
Code
Expected behavior:
No error.
Actual behavior:
Type '() => void' is not assignable to type '() => number'.
The same problem occurs inside a class. Manually annotating
m(): number
fixes the problem, but shouldn't we get that from the contextual type anyway?The text was updated successfully, but these errors were encountered: