-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Optional Chaining Edge Case #43748
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
To produce the expected behavior, set |
test is an empty array and |
The compiler doesn't know |
My issue is that Optional Chaining can return undefined. The following correctly identifies the error:
What I'm saying is that if you use optional chaining for assignment then the result can be a type or undefined and this is not picked up by Typescript for this specific scenario. |
Besides |
I think that covers the issue and I can close this. I didn't search hard enough to find it. |
Bug Report
Optional chaining is allowing undefined to be assigned to a variable that does not allow undefined.
π Search Terms
optional chaining
π Version & Regression Information
3.8.3
4.2.3
4.3.0
β― Playground Link
https://www.typescriptlang.org/play?ts=4.3.0-beta#code/PTAEHUFMBsGMHsC2lQBd5oBYoCoE8AHSAZVgCcBLA1UABWgEM8BzM+AVwDsATAGiwoBnUENANQAd0gAjQRVSQAUCEmYKsTKGYUAbpGF4OY0BoadYKdJMoL+gzAzIoz3UNEiPOofEVKVqAHSKymAAmkYI7NCuqGqcANag8ABmIjQUXrFOKBJMggBcISGgoAC0oACCoASMFmgY7p7ehCTkVOle4jUMdRLYTqCc8LEZzCZmoNJODPHFZZXVtZYYkAAeRJTInDQS8po+rf40gnjbDKv8LqD2jpbYoACqAEoAMsK7sUmxkGSCc+VVQQuaTwVb1UBrDYULY7PagbgUZLJH6QbYmJAECjuMigZEMVDsJzCFLNXxtajBBCcQQ0MwAUVWDEQNUgADVHBQGNJ3KAALygABEAAkYNAMOB4GRogLFFTBPB3AExcwABT0xnM9zsyhc9wASkp8GpNAUNPy11QlE4zAA2gBde180D2gDcsqNNLQ+lQACZzTSrba7U7TagbQAGO0AfgCiAYBBVnCZKF5AD5Bsm9W65QrIEr4KrQz6s8EVDgGh4yF5EJLnCD2Cb7oxrewGMxIPxYNB1IkufA9CIvAKGUyWYIBUkcQLwA5UAByYQAOUgEgFQRUAHlvmRdoIO1pIMdUI4FK5pHhQE4azpRlh9CgEIgYcIrt9JJLoiIDBwcd0WGwuG4IISiAA
π» Code
π Actual behavior
No errors reported.
π Expected behavior
test2 assignment should be flagged as an error as optional chaining can return undefined.
The text was updated successfully, but these errors were encountered: