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
Code
This is the sample code. I am going to print an http request value in the click event and output msg based on the returned code, but it is not successful.
interfaceStatusOK{code: 1;msg: string;}interfaceStatusNotOK{code: -1;}typeStatus=StatusOK|StatusNotOK;letrst: Status={code: 1,msg: 'OK'}if(rst.code===1){console.log(rst.msg);// okletelement=document.getElementById('code');if(element){element.addEventListener('click',function(){console.log(rst.msg);// Property 'msg' does not exist on type 'Status'.// Property 'msg' does not exist on type 'StatusNotOK'.})}}
I look forward to prompt the correct type
Expected behavior:
The results are the type of output an error.
Actual behavior:
Property 'msg' does not exist on type 'Status'.
Property 'msg' does not exist on type 'StatusNotOK'.
TypeScript Version: 3.0.1
Search Terms:
type guards
Code
This is the sample code. I am going to print an http request value in the click event and output msg based on the returned code, but it is not successful.
I look forward to prompt the correct type
Expected behavior:
The results are the type of output an error.
Actual behavior:
Property 'msg' does not exist on type 'Status'.
Property 'msg' does not exist on type 'StatusNotOK'.
Playground Link:
https://agentcooper.github.io/typescript-play/#code/JYOwLgpgTgZghgYwgAgMpjmArgZwPIDSyA3gFDLIID2AJhAFzICMA3OcgLY4DmjOYUUNzYBfUqVCRYiFOky4AclTCES7anUYBaVqTGkwATwAOsjNhzIAvGnO5VAH1vycSlQTakANhDDIo-IxyFtYkGgzMADScPIwA5IRx+sAwyAAUAWAAdOHWVjZMAJRqFNQgOFQ+WV5U3Bn8WVzchZ4UPn4QPhwQ4KE0VAhY3eBZ3L4Aol09YABChgCSNGlx4XEt7ClpnRDDYMVkFBTbu1lwNDTjAG7TADLA-D3QywhewAgA1nHRMFggCGDAKggNKFA6HcFlCpVGp1TKNHjrcEiQrsMQiIA
Related Issues:
#2214
The text was updated successfully, but these errors were encountered: