我有以下代码:
const RouterContext = createContext<IRouterContext>(null!)
VSCode不会出错,./node_modules/.bin/tsc --noEmit
也不会出错。然后,当我启动我的应用程序或尝试构建它时,出现错误消息:
Failed to compile.
./src/router/Router.tsx
Line 15: Parsing error: Unexpected token, expected ","
> 15 | const RouterContext = createContext<IRouterContext>(null!)
我正在使用a forked version of create-react-app,尽管变化不大。所以我想这与eslint有关,即使eslint-loader仅再次匹配test: /\.(js|mjs|jsx)$/,
。无论如何,我的配置如下:
module.exports = {
parser: '@typescript-eslint/parser',
extends: [
'plugin:@typescript-eslint/recommended', // uses typescript-specific linting rules
'plugin:react/recommended', // uses react-specific linting rules
'plugin:prettier/recommended', // enables eslint-plugin-prettier and eslint-config-prettier
'prettier/react', // disables react-specific linting rules that conflict with prettier
],
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},
project: './tsconfig.json',
tsconfigRootDir: './',
},
settings: {
react: {
version: 'detect',
},
},
rules: {
'@typescript-eslint/interface-name-prefix': 'always',
'@typescript-eslint/no-explicit-any': 'always',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/indent': 'off',
'@typescript-eslint/member-delimiter-style': {
delimiter: 'none',
requireLast: true,
},
},
}
我想念什么?