程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了React Typescript 类型转换问题 - 解析错误:缺少分号大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决React Typescript 类型转换问题 - 解析错误:缺少分号?

开发过程中遇到React Typescript 类型转换问题 - 解析错误:缺少分号的问题如何解决?下面主要结合日常开发的经验,给出你关于React Typescript 类型转换问题 - 解析错误:缺少分号的解决方法建议,希望对你解决React Typescript 类型转换问题 - 解析错误:缺少分号有所启发或帮助;

我有这行简单的代码:

const target = e.target as HTMLLIElement;

我收到此错误:

  line 18:28:  Parsing error: Missing semicolon
> 18 |     const target = e.target as HTMLLIElement;
     |                            ^

我查看了数十篇与我的问题类似的不同帖子,但没有一篇与我的问题完全吻合,或者他们的解决方案与我的项目并不真正相关。例如,有些人遇到了 eslint 问题,但我没有安装 eslint 包。这是我的 package.Json 文件:

{
  "name": "ally-autobot","version": "0.1.0","private": true,"dependencIEs": {
    "@craco/craco": "^6.1.1","@reduxJs/toolkit": "^1.5.1","@tailwindCSS/postCSS7-compat": "^2.1.0","@tesTing-library/jest-dom": "^4.2.4","@tesTing-library/react": "^9.3.2","@tesTing-library/user-event": "^7.1.2","@types/jest": "^24.0.0","@types/lodash": "^4.14.168","@types/node": "^12.0.0","@types/react": "^16.9.0","@types/react-dom": "^16.9.0","@types/react-redux": "^7.1.7","@types/react-router-dom": "^5.1.7","autoprefixer": "^9","firebase": "^8.4.2","firebase-tools": "^9.10.0","lint": "^0.7.0","lodash-core": "^4.17.19","postCSS": "^7","react": "^17.0.2","react-dom": "^17.0.2","react-firebase-hooks": "^3.0.4","react-redux": "^7.2.0","react-router": "^5.2.0","react-router-dom": "^5.2.0","react-scripts": "4.0.3","redux-persist": "^6.0.0","source-map-loader": "^2.0.1","tailwindCSS": "npm:@tailwindCSS/postCSS7-compat","typescript": "~4.1.5"
  },"scripts": {
    "start": "craco start","build": "craco build","test": "craco test","eject": "react-scripts eject"
  },"browsersList": {
    "production": [
      ">0.2%","not dead","not op_mini all"
    ],"development": [
      "last 1 Chrome version","last 1 firefox version","last 1 safari version"
    ]
  }
}

这是我的 tsconfig.Json 文件:

{
  "compilerOptions": {
    "sourceMap": true,"incremental": true,"target": "es5","module": "esnext","Strict": true,"noImplicitAny": true,"Strictnullchecks": true,"esModuleInterop": true,"forceConsistentCasingInfilenames": true,"lib": [
      "dom","dom.iterable","esnext"
    ],"allowJs": true,"skiplibcheck": true,"allowSyntheticDefaultimports": true,"nofallthroughCasesInSwitch": true,"moduleResolution": "node","resolveJsonModule": true,"isolatedModules": true,"noEmit": true,"Jsx": "react"
  },"include": [
    "src"
  ]
}

我也尝试过使用尖括号方法,但这不起作用,因为我在 tsx 文件中。我试过将 noImplicitAny 设置为 false。我已尝试在与此错误相同的文件中为所有表达式添加分号。

对如何解决此问题有任何想法吗?

解决方法

应该是eslint的错误。

将 eslintConfig 添加到 @H_427_5@m_velocity = Vector2D(200,0); Vector2D friction = FRICTION * m_velocity; m_velocity = m_velocity + friction * frametime; m_position = m_position + m_velocity * frametime; 可能会解决您的问题。 下面的设置是 create-react-app 的默认 eslintConfig

package.json
,

只需将 "parser": "@typescript-eslint/parser", 放在您的 eslint 配置文件中即可。

大佬总结

以上是大佬教程为你收集整理的React Typescript 类型转换问题 - 解析错误:缺少分号全部内容,希望文章能够帮你解决React Typescript 类型转换问题 - 解析错误:缺少分号所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。