When a property has exactly one type from an extends or implements clause, we should contextually type that property's initializer by the type from the clause. For example:
interfaceThingListener{handleEvent: (x: MouseEvent)=>void;}classFooimplementsThingListener{handleEvent=x=>{// No error, but this code is incorrectconsole.log(x.timestamp);}}Ideally we could take this one step further when widening. The following behavior is also undesirable:
interfaceHasLength{length: number}classFooimplementsHasLength{// length: any, not really what we intendedlength=undefined;}varx=newFoo();x.length='wat';// should not be allowede.g. #3666
When a property has exactly one type from an
extendsorimplementsclause, we should contextually type that property's initializer by the type from the clause. For example:Ideally we could take this one step further when widening. The following behavior is also undesirable:
e.g. #3666