no-undef-init vs init-declarations using try/catch
See original GitHub issueHow would you propose assigning data in a try/catch?
For instance:
let data;
try {
data = somethingThatCouldGoWrong();
} catch (error) {
// handle error
}
We currently disable @typescript-eslint/init-declarations
to overcome this problem.
Another workaround would be:
let data = undefined;
try {
data = somethingThatCouldGoWrong();
} catch (error) {
// handle error
}
But this would mean I need to disable no-undef
.
In Vue
, for example, the template needs the variable to always be defined before it can reliably be accessed.
This is an issue I bumped into while working on #577, but it seems too broad to mention there.
Issue Analytics
- State:
- Created a year ago
- Comments:8 (7 by maintainers)
Top Results From Across the Web
Error handling in R with tryCatchLog: Catching, logging, ...
The main advantages of the tryCatchLog function over tryCatch are: Easy logging of errors, warnings and messages into a file or console ...
Read more >tryCatch in R execute in case of error
Is it possible to execute certain commands in case of error when using tryCatch in R ? I am using the code below...
Read more >try...catch - JavaScript - MDN Web Docs - Mozilla
The try...catch statement is comprised of a try block and either a catch block, a finally block, or both. The code in the...
Read more >Basic Error Handing in R with tryCatch()
In this post we'll try to clarify a few things and describe how R's error handling functions can be used to write code...
Read more >Exceptions and debugging - Advanced R. - Hadley Wickham
tryCatch () is a general tool for handling conditions: in addition to errors, you can take different actions for warnings, messages, and interrupts....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@alexkramer98 I see. Let’s disable
init-declarations
and@typescript-eslint/init-declarations
for.vue
files in https://github.com/EvgenyOrekhov/eslint-config-hardcore/pull/577.@EvgenyOrekhov I would prefer
init-declarations
to be disabled. (Maybe just for.vue
files?).Unfortunately, your approach of keeping the variable in the scope of the try-block is not possible when that variable needs to be accessible in the template at some point when using the
composition API
(whichVue 3
has quite strongly moved towards).data
would not exist in the template.