Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.4k views
in Technique[技术] by (71.8m points)

react使用prettier无法使用类型断言

问题描述

使用react+ts,然后使用prettier进行代码格式化中使用类型断言一直会报Parsing error: Unexpected token, expected ","这个错误,请各位大神帮我看看eslint还要加什么配置才行?


错误截图

image.png

eslint配置

//.eslintrc.js
module.exports = {
    "env": {
        "browser": true,
        "es2021": true,
    },
    "extends": [
        "plugin:react/recommended",
        'prettier/@typescript-eslint',
        'plugin:prettier/recommended',
    ],
    "rules": {
        "prettier/prettier": ["error", { "endOfLine":"crlf" }],
    }
};

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

as string 去掉吧。
getCookie方法加返回属性:

getCookie = (): string => {//....}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...