【问题标题】:Parsing error: Unexpected reserved word 'interface'. eslint解析错误:意外的保留字 \'interface\'。 eslint
【发布时间】:2023-01-11 04:36:19
【问题描述】:

我正在尝试在我的代码中使用 Props,但在(接口 - “解析错误:意外的保留字'接口'。(3:0)eslint”)上出现以下错误。

我正在使用 Next 和 TypeScript 来开发这个项目。

error image

import { TitleStyled, SubTitle } from "./Title.style";

interface TitleProps {
    titulo: String;
    subtitulo?: String | JSX.Element;
}

export default function Title(props: TitleProps) {
    return (
        <>
            <TitleStyled>{props.titulo}</TitleStyled>

            <SubTitle>{props.subtitulo}</SubTitle>
        </>
    );
}

我的包.json

{
  "name": "pets",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@emotion/react": "^11.10.5",
    "@emotion/styled": "^11.10.5",
    "@mui/material": "^5.11.4",
    "@next/font": "13.1.1",
    "@types/node": "18.11.18",
    "@types/react": "18.0.26",
    "@types/react-dom": "18.0.10",
    "eslint": "8.31.0",
    "eslint-config-next": "13.1.1",
    "next": "13.1.1",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "typescript": "4.9.4"
  }
}

我的 tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
  "exclude": ["node_modules"]
}

【问题讨论】:

    标签: javascript reactjs typescript next.js


    【解决方案1】:

    您是否尝试过将文件重命名为 Title.tsx 而不是 Title.jsx

    【讨论】:

      猜你喜欢
      • 2021-11-18
      • 2019-12-25
      • 1970-01-01
      • 2017-07-31
      • 2022-01-02
      • 2017-11-21
      • 2017-07-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多