Typescript does not identify when a property can be undefined due to a safe operator being used #56608
Labels
Working as Intended
The behavior described is the intended behavior; this is not a bug
π Search Terms
"safe navigation operator", "optional chaining"
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play?#code/JYOwLgpgTgZghgYwgAgPICMBWyDeAoZZABzijgFsAuZAZzClAHMBuPAXzzzAE8iUNMqKADkA9mGQBeNFmQAfZAFcQAEwgxQEFazwAbCBJijR1AULFgdCUSBqj9AOl2jGACiOiA-A5JlyASmZkAHpg5B4+GgQGIgkAaxBRAHcacIALOAlfCmRrRV0VZHQUOgYQRmRRKCVVdU1CtOgIBwc8a1t7Zuc3D29s8gcaXWAkV39AkLCIiCiYiRo00XzC63IiXThQZEaoCAAaYlIc8jhuIpRlNQ0QLWQ4VWREiThaeiYHIA
π» Code
π Actual behavior
typescript allows
.slice()
to be called onparam
π Expected behavior
typescript should give an error when calling
.slice()
onparam
becauseparam
may be undefined because of the safe navigation operator before it.Additional information about the issue
Seems related to but still a bit different from this issue: #53872
The text was updated successfully, but these errors were encountered: