Uh oh!
There was an error while loading. Please reload this page.
fix(47383): Destructuring of unknown catch variable is not an error - #47442
fix(47383): Destructuring of unknown catch variable is not an error#47442Oleksandr Tarasiuk (a-tarasyuk) wants to merge 0 commit into
Conversation
Uh oh!
There was an error while loading. Please reload this page.
Jake Bailey (jakebailey)
commented
Jan 19, 2022
This PR does pass tests, but I'm a bit confused as to why it doesn't work when I run the build via tsserver locally in VS Code; do these sorts of checks need to be somewhere else, maybe? Some missing case in another function? |
Jake Bailey (jakebailey)
commented
Jan 19, 2022
Hm, apparently |
Jake Bailey (jakebailey)
commented
Jan 20, 2022
Yeah, I think |
Jake Bailey (jakebailey)
left a comment
There was a problem hiding this comment.
Marking as needing changes (meant to do this with my last comment), as this doesn't seem to work in VS Code (and probably other editors), so we'll need to make sure that check call is added. Not entirely certain how to ensure the tests actually walk that; maybe they already check the opposite?
18988f3 to
40964a3CompareOleksandr Tarasiuk (a-tarasyuk)
commented
Feb 1, 2022
Jake Bailey (@jakebailey) Thanks for the review and sorry for the delay in response. I've added changes that cover the following cases // @strict: true// @useUnknownInCatchVariables: truetry{// ...}catch({ name }){^^^^Property'name'doesnotexistontype'unknown'// { name } has 'unknown' type because @useUnknownInCatchVariables: truename;}try{// ...}catch({ name } : unknown){^^^^Property'name'doesnotexistontype'unknown'// { name } has explicit type 'unknown'name;}// @strict: true// @useUnknownInCatchVariables: falsetry{// ...}catch({ name }){// Ok// { name } has 'any' type because @useUnknownInCatchVariables: falsename;}try{// ...}catch({ name } : unknown){^^^^Property'name'doesnotexistontype'unknown'// { name } has explicit type 'unknown'name;}// @strict: false// @useUnknownInCatchVariables: truetry{// ...}catch({ name }){^^^^Property'name'doesnotexistontype'{}'// { name } has '{}' type because @useUnknownInCatchVariables: true// `unknown` is represented as `{}` with disabled `strict: false` checkname;}try{// ...}catch({ name } : unknown){^^^^Property'name'doesnotexistontype`{}`// { name } has explicit type 'unknown'name;}// @strict: false// @useUnknownInCatchVariables: truetry{// ...}catch({ name }){// Ok// { name } has 'any' type because @useUnknownInCatchVariables: falsename;}try{// ...}catch({ name } : unknown){^^^^Property'name'doesnotexistontype`{}`// { name } has explicit type 'unknown'name;}Is this the expected behavior? Or do we need to cover other cases? |
Unless I'm mistaken, all of the examples above should have It looks like things are still not quite right in the editor, though. If you use your test case but don't reference the variable in question, it still doesn't show an error. Compare the three cases here, each with the destructured variable left referenced. const{ xyz }: unknown={};functionfoo({ name }: unknown){// ...}try{// ...}catch({ name }: unknown){// ...}I'm not sure what you've changed to get further is correct, though; it still feels to me like there's something missing during the checker walk, and these errors are only functioning due to the side effect of evaluating the variable later. |
40964a3 to
cc88521CompareUh oh!
There was an error while loading. Please reload this page.
cc88521 to
4ea6586CompareUh oh!
There was an error while loading. Please reload this page.
474027f to
5599944CompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
5599944 to
07ff1dcCompare07ff1dc to
aaacfbeCompareaaacfbe to
ba55fcfCompareI'm confused about the state of this PR. Why is it marked draft? If a team member signs off, is it OK to merge? If so, I guess that means it needs another review? |
ba55fcf to
54fa69cCompareNathan Shively-Sanders (@sandersn) I'm really sorry for the confusion with the state of the PR. I've closed it to make this issue open to PR acceptance. |

Fixes#47383