You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Can't implement interface by throwing error #16874
Check out #16608 and #8767 for changes/discussion related to this. We could fix this with a voidWideningNever type, or by just checking for a contextual type.
Daniel Rosenwasser (@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 void and never.
I'm actually fine with getting an error in this case:
classBase{overrideMe(){thrownewError("You forgot to override me!");}}classDerivedextendsBase{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 void will just mislead someone who has a reference of type Base.
Asad Saeeduddin (@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 void here is that no one can meaningfully misuse a void value obtained via a Base instance reference. Conversely, you can trivially misuse a never value because it's e.g. a valid function argument to any parameter position. It's worth considering the case where the author of Base does not have any Deriveds in their codebase (because they're shipping a base class library) -- they won't realize they have a "missing" type annotation until one of their consumers shows up complaining.
Re: another flag... this is not something that would be worth doubling the configuration space of TypeScript over.
Activity
DanielRosenwasser commentedon Jun 30, 2017
Check out #16608 and #8767 for changes/discussion related to this. We could fix this with a
voidWideningNevertype, or by just checking for a contextual type.I'm only half-joking.
RyanCavanaugh commentedon Jun 30, 2017
These should be identical:
masaeedu commentedon Jul 9, 2017
Daniel Rosenwasser (@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
voidandnever.I'm actually fine with getting an error in this case:
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
voidwill just mislead someone who has a reference of typeBase.RyanCavanaugh commentedon Jul 9, 2017
Asad Saeeduddin (@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
voidhere is that no one can meaningfully misuse avoidvalue obtained via aBaseinstance reference. Conversely, you can trivially misuse anevervalue because it's e.g. a valid function argument to any parameter position. It's worth considering the case where the author ofBasedoes not have anyDeriveds in their codebase (because they're shipping a base class library) -- they won't realize they have a "missing" type annotation until one of their consumers shows up complaining.Re: another flag... this is not something that would be worth doubling the configuration space of TypeScript over.