eslint-plugin-strict-null-checks icon indicating copy to clipboard operation
eslint-plugin-strict-null-checks copied to clipboard

Possible issue with typings where the parameters can be `null`.

Open TheBox193 opened this issue 2 years ago • 5 comments
trafficstars

Seems that the checker is not picking up on a libraries typings where the parameters can indeed be null.

Don't pass nullish arguments to a function that expects a non-nullish type.eslint[strict-null-checks/all](file:///all)

image

image

TheBox193 avatar Feb 10 '23 00:02 TheBox193

Are non-imported functions working correctly? For example does adding this not generate a warning?:

function foo(value: {value: number} | null) {}
foo(null);

JaroslawPokropinski avatar Feb 11 '23 15:02 JaroslawPokropinski

First off, thanks for your work on this plugin @JaroslawPokropinski.

Just ran into this as well with a slightly different usage (function param initializers), and I can confirm it doesn't work for non-imported functions. Here's a trivial example: Screen Shot 2023-02-23 at 15 30 53

In that example, TS tweaks the type of foo from what we defined it as to const foo: (bar?: number) => number because of the bar = 2 initializer.

If you have any hints about where to get started debugging this I can take a crack at submitting a PR.

doytch avatar Feb 23 '23 20:02 doytch

Hello @doytch, have you been able to find the root cause of this issue ?

I'm also have this other issue (that look familiar).

image

neolectron avatar Oct 10 '23 15:10 neolectron

That’s an odd one. But no, I never found a solution.

What I ended up doing is stopping use of this plugin in our org and used an interesting little feature in VSCode instead since almost all of us use it.

I added a nested tsconfig in our codebase. That is, if our normal tsconfig was at the project root ~, I put a new tsconfig in ~/src.

That tsconfig simply inherited the main tsconfig but turned on strictNullChecks. Absolutely nothing uses a nested tsconfig file by default - except VSCode’s TS server.

So that showed everybody errors during development but didn’t break builds. That may or may not meet your requirements (and I thiiink we might’ve been relying on undocumented VSCode behaviour so it’s not reliable long-term), but just figured I’d throw it out there.

doytch avatar Oct 11 '23 12:10 doytch

That's a freaking awesome tips you got right there, thank you for sharing this, I think I will go for this too. The ratio simplicity / efficiency is right where I need it to be. Have a great day!

neolectron avatar Oct 16 '23 11:10 neolectron