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
Typescript + React + Context.Provider = TypeError: Cannot read property 'variables' of null #2882
Comments
What is the failure? You haven't provided it yet. |
Also, what version of react are you using? React 17 uses a different jsx transform. With the "legacy" jsx transform, you have to enable the |
You're right, @ljharb! I updated the description with the package.json and the error output. Here is the error output again:
I was using React 17, so I switched to 16 and the error remains the same, unfortunately. |
I'm unable to reproduce this - your test case passes with babel-eslint as well as with both the old and new TypeScript eslint parsers. Can you provide the exact, unedited contents of |
@ljharb App.tsx in the example is exactly the same as hello.tsx locally. I've tried changing typescript versions and react versions, but I consistently get this error. I've created a repo that demonstrates it. I was able to remove the directory locally and re-clone it, and running eslint still produces the error. Here's the demonstration repo: https://github.com/stevematney/eslint-clash Thank you for your help! |
Also, if it helps, I'm running node on v15.4.0. |
Thanks, I'm able to reproduce it locally :-) once i get that turned into a test case, i should be able to land a fix. |
That’s excellent! Thank you! |
Hmm, this is very confusing. The error in your repo goes away when I comment out The issue seems to be that somehow the "scope" object eslint is seeing doesn't have a I have a fix, but I'm hesitant to land it without a regression test :-/ |
I believe what we've discovered is actually either a bug or an unclarity in @typescript-eslint. Their docs say that This code is how they're parsing the version, and it looks like what's happening is it eventually evaluates the version I've listed as I set the |
aha! That makes sense. That might help me figure it out.
|
When I set ecmaVersion to 5, I get |
It's interesting that you get a different error. If I just change Do you think this still represents a bug in the plugin, since it's breaking on es5 in this scenario, or is this simply a scenario that should never happen if you're intentionally targeting es5? |
I think it's a scenario that should never happen, and you might be right that RuleTester is stricter than the CLI is, out of necessity. I'll land the fix anyways, since it doesn't hurt, but i do think that the typescript parser should be erroring out when the ecmaVersion isn't high enough - |
That's true. It seems interesting that it "supports" es5 when TS is very heavily geared toward writing in post-es6 syntax. That said, I think it's theoretically possible to write very simple es5 code and include Type information, and it should still function fine. Something like: interface Vehicle {
canDrive: boolean;
}
var myCar: Vehicle = { canDrive: true }; That's fully valid es5 code and fully valid TypeScript (I think), so there shouldn't be an issue attempting to lint it. I think I would hope to see an error earlier in the process when my |
Our underlying parser doesn't respect the ecmaVersion parserOption. The intention was never that the parser be used as a validation tool like it is for plain JS. Additionally - ecmaVersion is an odd concept when it comes to typescript considering that it will (similar to babel) allow you to write any code and have it transpiled down to a target version. Setting ecmaVersion to 5 for TS is pretty meaningless. So for TS - writing We have only recently added some handling for the ecmaVersion. That handling is only in the scope manager, and it is kind of just a backwards compatibility thing due to the fact that our scope manager is essentially a fork of |
@bradzacher that's a totally fair point - it seems like this bug is indeed caused by something in the scope manager. Perhaps your fork of eslint-scope could be made to ignore the parserOptions.ecmaVersion (since i'm assuming what's happening here is that it's not ignoring it)? |
yeah so essentially what happened here is that the code is just super naive assumes ecmaVersion will be a number or nullish. Because And then the "is ES6" check fails because But yeah - it should 100% just ignore |
eslint is failing when using
@typescript-eslint/eslint-plugin
andeslint-react-plugin
together. This failure seems to only happen when attempting to render a Provider from a Context as jsx.If I disable
react/jsx-no-undef
, it works, and I can fall back to tsc or tsserver to catch JSX undefined errors, but then eslint itself becomes silent on the issue. Here's the configuration I've got in a stripped down project to produce the error. All the relevant files are listed below, and here is a repo which demonstrates the issue: https://github.com/stevematney/eslint-clashI would be happy to hear if I'm just doing something incorrectly, but this does seem to be a bug.
Thanks!
The text was updated successfully, but these errors were encountered: