Stripped down demonstration - GitHub
We currently have a create-react-app project that is undergoing an incremental migration from Flow to Typescript. This meant disabling some undesirable ESLint rules. In order to customise ESLint, I've added EXTEND_ESLINT=true to the .env file.
Before adding this setting, my Typescript code compiles fine. Afterwards, I get parsing errors on certain (but not all) Typescript grammars.
// Type guards
export function f0<T>(x: T|undefined): x is T { ...
// Constrained generics
export function f1<T extends number>(x: T) { ...
// Type assertions
... return x as T
There may be other unrecognised syntaxes I haven't found yet.
So far
I haven't found any similar problems or bug reports. I understand some Typescript features are not available in the current CRA version, such as
const enum, but I haven't found any mention of the features listed above. I am also pretty sure my Typescript and ESLint versions are compatible withtypescript-eslint.I've tried many different
.eslintrccombinations. I've left a few of the most promising in the.eslintrc.jsfile in the attached repository. The current setup is the one recommended by create-react-app, where Typescript linting is set up in theoverridessection.The ESLint Typescript configuration was set up following instructions from the
typescript-eslintmonorepo, in particular,typescript-eslint/parserandtypescript-eslint/eslint-plugin
Solutions
Ejecting is not an option. If no other solution can be found, I would rather just do the Flow -> TS conversion in one go.
We currently extend our CRA configuration with customize-cra. Solutions involving this are welcome.
I enjoy the flexibility the
.eslintrcgives me but I am happy to do away with it, provided I can still set lint rules.
Notes
I've included
customize-crain the demo repo to accurately reflect our project, but the problem persists withoutcustomize-cra, indicating that it is likely not the culprit.See
src/components/TestComponent/fn.tsfor examples of the problem syntax.My current hypothesis is that there's some setup in the CRA ESLint config that doesn't get carried over when
EXTEND_ESLINT=true.
Updates
- I've opened an issue at create-react-app
- Partial workaround listed on the issue. Still not ideal.