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
TypeScript Version: 2.9.2, 3.1.1 (didn't try any other)
Search Terms: this type keyof this
Code
interfaceFoo{foo: number;}interfaceBar{bar: number;}typeFooBar=Partial<Foo&Bar>;typeFooBarMap<TextendsFooBar>={[PinExtract<keyofFooBar,keyofT>]: string};declarefunctionmap<TextendsFooBar>(o: T): FooBarMap<T>;classAimplementsFoo{foo=1;map=map(this);constructor(){console.log(this.map.foo)// unexpected: Property 'foo' does not exist on type 'FooBarMap<this>'.console.log(this.map.bar)// expected: Property 'bar' does not exist on type 'FooBarMap<this>'.}}classBimplementsBar{bar=1;map=map(thisasB);constructor(){console.log(this.map.foo);// expected: Property 'foo' does not exist on type 'FooBarMap<B>'.console.log(this.map.bar);}}
Expected behavior: map(this) should be the same as map(this as A) for class A;
Actual behavior:
See code above or Playground.
I suspected the problem might be keyof this vs. keyof A, but I didn't manage to reduce the problem to it so I'm not sure.
I think this is the same problem as #27883. { [P in Extract<keyof FooBar, keyof T>]: string }; should contain at least "foo", but we don't have a way to represent that.
@andy-ms
I must admit, I don't think I fully grasp the issue you referenced, but I'm not sure they are related.
My problem here is that map(this) infers to map<this>(this) and it behaves differently than map<A>(this), i.e. when I use the explicit forms map<A>(this) or map(this as A) then it works as expected. But from my understanding the type this and the type A should behave the same, at least in the case above, or not?
TypeScript Version: 2.9.2, 3.1.1 (didn't try any other)
Search Terms:
this
typekeyof this
Code
Expected behavior:
map(this)
should be the same asmap(this as A)
for classA
;Actual behavior:
See code above or Playground.
I suspected the problem might be
keyof this
vs.keyof A
, but I didn't manage to reduce the problem to it so I'm not sure.Playground Link:
Link
Related Issues:
#24791
The text was updated successfully, but these errors were encountered: