// @strictNullChecks: trueinterfaceOnChanges{onChanges(changes: Record<string,unknown>): void}interfaceValidator{validate(): null|Record<string,unknown>;}classC{validate(){return{}}}functionfoo(){letv: Validator&Partial<OnChanges>=nullasany;if(vinstanceofC){}if(v.onChanges){// error herev.onChanges({});}}No error.
Property 'onChanges' does not exist on type 'C | (Validator & Partial<OnChanges>)'.
Property 'onChanges' does not exist on type 'C'.
TypeScript Version: 3.4.*
Search Terms:
instanceof
Code
Expected behavior:
No error.
Actual behavior:
instanceofshouldn't change the type of the variable outside of theifstatement.This only happens with
strictNullChecksenabled.Playground Link:https://typescript-play.js.org/#code/JYOwLgpgTgZghgYwgAgPIgMIAs4gOYQDOyA3gFDKXID2mO+RAFAvQYQFzIBKEC1UAEwA8hMFFB4ANMgCuIANYhqAdxAA+AJScAbtWACyAXzKhIsRCgBqcADb64YfqQpVtt+5EZbkIGTZvIAD7cvPzCouL40nKKKuoA3EZkZAg2cITEGM5UyG52Ag4QXtk5VFAQYDJQIKTGOcbGMHIIYMC0yDDU1MXkOTYVuZzW+Q5OAGTIAApwUK22QujYuGxqyAC8Pn4B6ci4AJ6JOcAwyIzayKCiuEjUJxgaJZR1VMen2gB0tEsMhA+9pZQPl9WEwSIYNIcqA0gA
Related Issues: