Skip to content
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

Open
xandris opened this issue Aug 13, 2024 · 6 comments
Open

Comments

@xandris
Copy link

xandris commented Aug 13, 2024

Given a stock config, local variables that may be undefined are impossible to lint:

// Variable 'x' should be initialized on declaration
// @typescript-eslint/init-declarations
let x: number | undefined

// It's not necessary to initialize 'x: number | undefined' to undefined
// no-undef-init
let x: number | undefined = undefined

The safer route is probably to turn off no-undef-init and allow superfluous initialization with undefined? At least in Typescript.

@mightyiam
Copy link
Owner

Sorry about this. And thank you for raising it. Will take a look. Perhaps this weekend.

@xandris
Copy link
Author

xandris commented Aug 15, 2024

I actually ended up turning off @typescript-eslint/init-declarations because for our codebase the problem it prevents is already caught by the Typescript compiler (TS2454 Variable is used before being assigned)

@mightyiam
Copy link
Owner

Thank you for the additional feedback, @xandris.

@mightyiam
Copy link
Owner

Analysis with @rostislav-simonik conclusion:
Both rules are desirable, except that typescript-eslint/typescript-eslint#9950.

@xandris would you concur?

We suggest waiting for upstream's response.

@xandris
Copy link
Author

xandris commented Sep 7, 2024

yes, i agree completely

@mightyiam
Copy link
Owner

typescript-eslint/typescript-eslint#9950 (comment)

@xandris say... how many of these do you have? Could they possibly be nicer as null instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

2 participants