I noticed that build 4.0.0-dev.20200520 broke eslint parser (or whatever/however it's called; more info follows).
This build introduced changes that break my eslint parser as well.
TypeScript Version: (versions with ✓ work as expected)
x 4.1.0-dev.20200909 (typescript@next)
x 4.0.2 (latest release)
x 4.0.0-dev.20200520
✓ 4.0.0-dev.20200519
✓ 3.9.7
Search Terms: parsing error, eslint
Code
Here's a rather simple (one of) file that I have where parser throws error:
import React from 'react';
function useFocus(): [
boolean,
{
onFocus: (e: React.FocusEvent) => void;
onBlur: (e: React.FocusEvent) => void;
},
] {
const [isFocused, setFocused] = React.useState(false);
const bind = React.useMemo(
() => ({
onFocus: (): void => setFocused(true),
onBlur: (): void => setFocused(false),
}),
[],
);
return [isFocused, bind];
}
export default useFocus;
/Users/viktor/Developer/Ruby/CivicLift/app/javascript/hooks/useFocus.ts
0:0 error Parsing error: Cannot read property 'map' of undefined
EDIT: I managed to shorten this down to this tuple line:
const a = (): [boolean, boolean] => [false, true]
This is how I run this from package.json:
{
"scripts": {
"fix-js": "eslint --fix -c .eslintrc.js --ext .jsx,.js,.ts,.tsx app/ spec/"
}
}
I tried running this with tsc, (node_modules/.bin/tsc -p tsconfig.json), but then useFocus doesn't come out as one of the errors. Maybe tsc skips useFocus?
Playground Link:
I don't know how to get this working in playground:
https://www.typescriptlang.org/play?noEmitHelpers=true&target=1#code/JYWwDg9gTgLgBAJQKYEMDG8BmUIjgcilQ3wG4AoczAVwDsNgJa5qBnJAMQjTYAoBKAFxwA2uThwARhAgAbVLQA04uAG8VEplx6thvJMOToYAOm1sAogDcktGPzgBeAHxwrEYABMKEzbQBCstRQegaIxKbmrNa29k6u7l4+cAC+ygC6aipoTKzwIsCsUUieinDsMMWemY7hxiZsSADKMCgwSLyYKLLs-BTZufCSwLSeTnUYDewAskggELwacALxy+q+vlrcbHpCbh5jLuVIldvsnrwwUNRI-MobfoHBu8KJh64VVZ3dvfe+KXcliJ0n8+pQJEQYMFmAUimcSmVhqN0hQUpQkAAPSCwOCeJBdaiyeCNKIUIA
Related Issues:
https://github.com/microsoft/TypeScript/issues/38682
@weswigham had some insight into this issue?
Thank you!
.elementTypes was renamed to .elements on tuples in the AST of 4.0, to account for labeled elements.
I'm searching online, but I can't find much info about this.
Where should I look further?
Should I post this issue to one of eslint package repos and they would know what to do?
I searched my entire codebase and couldn't find any reference to .elementTypes.
Ok, I searched through node_modules and found which package is throwing this error.
Then I upgraded TS to latest version along with eslint and its packages and, after digging through another error, figured out a way to fix it all (had to fix @typescript-eslint/parser to v4.0.1, as v4.1.0 seems to be breaking some things).
Either way, I'm on TypeScript v4 and my eslint still works! :)
I'll close this issue as it's probably more related to @typescript-eslint/parser and they are aware of the issue.
Thanks!
Most helpful comment
I'm searching online, but I can't find much info about this.
Where should I look further?
Should I post this issue to one of eslint package repos and they would know what to do?
I searched my entire codebase and couldn't find any reference to
.elementTypes.Ok, I searched through
node_modulesand found which package is throwing this error.Then I upgraded TS to latest version along with eslint and its packages and, after digging through another error, figured out a way to fix it all (had to fix @typescript-eslint/parser to v4.0.1, as v4.1.0 seems to be breaking some things).
Either way, I'm on TypeScript v4 and my eslint still works! :)
I'll close this issue as it's probably more related to @typescript-eslint/parser and they are aware of the issue.
Thanks!