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
interfaceAEvent{foo: number;}interfaceBEventextendsAEvent{bar: number;}exportdeclareinterfaceAEventMap{'event': AEvent;}exportdeclareinterfaceBEventMapextendsAEventMap{'event': BEvent;}classA<EventMapextendsAEventMap=AEventMap>{listeners: Array<(e: EventMap['event'])=>void>=[];addListener(listener: (e: EventMap['event'])=>void){this.listeners.push(listener);}triggerEvent(e: EventMap['event']){for(constlistenerofthis.listeners){listener(e);}}run(){this.triggerEvent({foo: 1});// Should throw TS2345.}}classBextendsA<BEventMap>{}constb=newB();b.addListener((e)=>console.log(e.bar));// 'bar' may not exist.b.run();
Expected behavior:
TS2345 should be thrown at the this.triggerEvent({ foo: 1 }); statement because EventMap['event'] could be a subtype of AEvent, in which case { foo: 1 } cannot assign to it.
Uh oh!
There was an error while loading. Please reload this page.
TypeScript Version: 3.9.2
Search Terms:
TS2345
generic type
lookup type
Code
Expected behavior:
TS2345 should be thrown at the
this.triggerEvent({ foo: 1 });
statement becauseEventMap['event']
could be a subtype ofAEvent
, in which case{ foo: 1 }
cannot assign to it.A simplified version of the code without lookup types gets an error correctly.
https://www.typescriptlang.org/play/#code/JYOwLgpgTgZghgYwgAgIIFEBuFzIN4CwAUMsjAPbkBcyIArgLYBG0A3MQL7HGiSyIoAQlhxhkEAB6QQAEwDOaEbkIlkTOFBr1mbTtyIIANnDkLUAHiVjJ0+Yuy4AvPdEA+fMVKHgc6dDk0qFBQcACe5gAUEDRWAJTIju6Y5MAy7s4A2gC67ESeyHAyMgAyPn5QEd6+ONA0UTEOYPGJyMmp8SqkpGAAFj4AdFXlcv0ADnRyPZVlNVCxuaRceapgUMAA5uvQVvXIcR6qpBRQyBEI5CC+yEOzyOQwyL0DNyD+Hfld1zOvFRDzH8glot9KQoHQQBF3odHn0RqsNlsoDs8GRKDQAIyA+akAD0OOQABUelByAB3BQEgDKACYAMwAFgArP18kslsQjCYFIJxFIcHYLMJGu48OyDBcrkwErQIKTkIJIbkmP1CiVvtAIlFmu5zpdyIYIINyOsov11HNscg8cgAOTmm3IBhhWjkawSMos5bKsEQ-5EIA
Actual behavior:
No compilation error.
Playground Link:
https://www.typescriptlang.org/play/#code/JYOwLgpgTgZghgYwgAgIIFEBuFzIN4CwAUMsjAPbkBcyIArgLYBG0A3MQL7HGiSyIoAQlhxhkEAB6QQAEwDOaEbkIlkTOFBr1mbTtyKSADuShiZEBABsNKXtHhJF2cAFk4h-MVIByCM7DeNBj+7ERcRMRGJmYW1lC24PYCyML+bh6S0vJOoumeqr7+gSlKYKHhxFZwcgqoADyleZk42cG57sgAvDmu7gB8+aSWwHLS0HJBUFBwAJ51ABQQNI3uANqFot4AugCUXQOY5MAyA92rW6FeyHAyMgAyI2NQ88OjONA0i8tpaxvg23tOgcjjI9ipSKQwAALEYAOleTzksMMdDkUJej3eUB2oVIFVUYCgwAA5sToKUvsgVoZ1n5NrtBhCKFBkPMEOQQKNkAischyDBkNC4TyQOMwVcIdzMaLnhAcRLkOE8fpSFA6CB5uLVJCYUjCSSyVAKXgyJQaABGRU40gAehtyAAylDyHRLDJBVCoOQAO7IAAqDoATABmAAsAFZYVdwviqjUUuIpC1anVUu1DAM8LGOVymF1aBBfYJNaEmLCbvdpdB5otAQN2ZzyJYIPDyMTFrD1Njrcg7chvF3vMgGLNaOQxJJHlGIkQy2qNfKiEA
Related Issues:
I could not find.
The text was updated successfully, but these errors were encountered: