-
-
Notifications
You must be signed in to change notification settings - Fork 69
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
Rule clash between @typescript-eslint/init-declarations and no-undef-init #1710
Comments
Sorry about this. And thank you for raising it. Will take a look. Perhaps this weekend. |
I actually ended up turning off |
Thank you for the additional feedback, @xandris. |
Analysis with @rostislav-simonik conclusion: @xandris would you concur? We suggest waiting for upstream's response. |
yes, i agree completely |
typescript-eslint/typescript-eslint#9950 (comment) @xandris say... how many of these do you have? Could they possibly be nicer as |
Upstream locked the issue so I think the lesser evil is to disable init-declarations. At least that's what I did. |
not many... it's usually like an initializer that's too complex for a ternary. the variables are not actually nullable; they really do get assigned before use and the compiler does enforce that |
Thank you @darkbasic and @xandris . "not many" leads me towards eslint-disable comments. Thoughts on that? |
@mightyiam I use |
@darkbasic could I possible trouble you to provide some example, please? |
@mightyiam for example in the project I'm currently working right now I need to share some variables between different event listeners to make vuetify tables resizable. I need to create these variables upfront and I cannot initialize them with anything else but undefined: |
@darkbasic why not |
@mightyiam there are cases where null might be a valid value that could be set and there would be no way to tell if the variable has been assigned or not. |
The problem is that until this will be properly fixed Typescript doesn't create a union with |
@darkbasic perhaps it's appropriate in the case you mentioned to disable the rule ad-hoc for some limited scope, or even the entire project. See a recent readme section: I don't see a valid reason to disable the rule, though. Please try to prove me wrong if I'm wrong. |
Let's try the other way around: what do you think is the value of
The reason is that Typescript is not able to infer |
The value of It seems that in TS, as opposed to in JS, some cases are not equivalent. Is this correct? |
There are non equivalent cases in JS as well: think of a loop where you are using a non block-scoping statement like |
Thank you, @darkbasic. |
## [89.0.1](v89.0.0...v89.0.1) (2024-10-20) ### Bug Fixes * rm no-undef-init ([7038ca4](7038ca4)), closes [#1710](#1710)
🎉 This issue has been resolved in version 89.0.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Given a stock config, local variables that may be undefined are impossible to lint:
The safer route is probably to turn off no-undef-init and allow superfluous initialization with
undefined
? At least in Typescript.The text was updated successfully, but these errors were encountered: