Hi I have probleb with ESLINT setup, for my TS, expo, react-native project.
I have added TS, import type, and have ‘parsing error’ from standard.
my configs:
babel.js:
module.exports = function (api) {
api.cache(true)
return {
presets: ['babel-preset-expo', ]
}
}
tsconfig.json
{
"extends": "expo/tsconfig.base",
"compilerOptions": {
"strict": true
}
}
and .eslintrc.js
module.exports = {
env: {
browser: false,
es2021: true
},
extends: [
'plugin:react/recommended',
'standard-with-typescript'
],
parser: '@typescript-eslint/parser',
overrides: [
{
files: ['*.ts', '*.tsx'], // Your TypeScript files extension
// As mentioned in the comments, you should extend TypeScript plugins here,
// instead of extending them outside the `overrides`.
// If you don't want to extend any rules, you don't need an `extends` attribute.
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking'
],
parserOptions: {
project: ['./tsconfig.json'] // Specify it only for TypeScript files
}
}
],
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module'
},
plugins: [
'react',
'@typescript-eslint'
],
rules: {
}
}
What happened here and how can I remove that error in my VS Code?
2
Answers
I guess the error is given the way you are importing
FC
and it is not ESLINT related:Please, try that approach:
References: react-native-docs
If you’re not yet on TypeScript 4.5,
import { type Foo } from "bar"
is not a thing. It should beimport type { Foo } from "bar"
. See the section of the TypeScript 3.8 release notes that introduced the "Type-Only Imports" feature and the TypeScript docs’ section on "Importing Types"You can’t mix type-only imports and non-type-imports in the same import statement. Again, see the section of the TypeScript 3.8 release notes that introduced the "Type-Only Imports" feature:
You should separate the type-only imports and non-type-imports into separate import statements.
However, if you’re on TypeScript 4.5 or later, this should be working for you:
This is a TypeScript lanugage feature described in the v4.5 release notes.
There was mention that it would take time for other tooling to support the new syntax.
For babel, support should be there now: https://github.com/babel/babel/issues/13799 and https://github.com/babel/babel/pull/13802.
I’m not sure about ESLint. There’s a related issue ticket about exports here: https://github.com/typescript-eslint/typescript-eslint/issues/3597