Welcome to OStack Knowledge Sharing 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 Answer

0 votes
by (71.8m points)

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

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...