Type Guards on this
should affect type parameters
#28889
Labels
Question
An issue which isn't directly actionable in code
Uh oh!
There was an error while loading. Please reload this page.
TypeScript Version: 3.2.1-insiders.20181128
Search Terms: type guard this generic
Summary
In a
class MyClass<T>
, a type guard of the formthis is MyClass<T & Foo>
should constrainT
to extendFoo
.Alternative
It might make more sense to instead allow type guards on generic parameters; eg,
isFoo(): T is Foo
.Code
Expected behavior:
Inside
if (this.hasBar())
,TWith
should be constrained to extendWithBar
andoptions.bar
should exist.Actual behavior:
options
still has no properties.With stricter compilation options,
this.whatIsTWith
has conflicting definitions.Playground Link: Link
Related Issues: #14817
The text was updated successfully, but these errors were encountered: