reactjs - 在 vscode 中的 redux reducer 中出现 Typescript 注释错误,即使我没有在 Typescript 中编写任何内容
问题描述
在我的 reducer 文件中,这种类型的所有声明
const newValue: action.payload.value;
都带有红色下划线,并且 VSCODE 会抛出一个编译器错误,上面写着:“类型注释只能在 TypeScript 文件中使用。”
但是,我根本没有在我的 create-react-app 项目中指示或配置任何应该检查打字稿语法的东西。
这打破了我的应用程序,不知道为什么。
import * as types from "../actions/actionTypes";
const initialState = {
firstName: "",
lastName: "",
userName: "",
email: "",
password: "",
confirmPassword: ""
}
const userReducer = (state = initialState, action) => {
switch(action.type) {
case types.UPDATE_USER: {
const newFirst: action.payload.firstName;
const newLast: action.payload.lastName;
const newUserName: action.payload.userName;
const newEmail: action.payload.email;
const newPass: action.payload.password;
const newConfirmPass: action.payload.newPassword;
return {
...state,
firstName: newFirst,
lastName: newLast,
userName: newUserName,
email: newEmail,
password: newPass,
confirmPassword: newConfirmPass
}
}
default:
return state;
}
}
export default userReducer;
VSCODE 终端错误:
Failed to compile.
./src/reducers/reducer.js
Line 15:47: Parsing error: Unexpected token
13 | switch(action.type) {
14 | case types.UPDATE_USER: {
> 15 | const newFirst: action.payload.firstName;
| ^
16 | const newLast: action.payload.lastName;
17 | const newUserName: action.payload.userName;
18 | const newEmail: action.payload.email;
浏览器错误:
index.js:1 ./src/reducers/reducer.js
Line 15:47: Parsing error: Unexpected token
13 | switch(action.type) {
14 | case types.UPDATE_USER: {
> 15 | const newFirst: action.payload.firstName;
| ^
16 | const newLast: action.payload.lastName;
17 | const newUserName: action.payload.userName;
18 | const newEmail: action.payload.email;
解决方案
推荐阅读
- java - 关于 Java 嵌套 Enum 类型
- android - 未解决的参考:android build failed with kotlin dsl(可在空项目中重现)
- dart - 为什么 Dart 中的类构造函数有一个冒号 (:)?
- php - php解析没有create_function和eval的函数
- matlab - 如何在图像中将人体与背景分开
- python - 如何将多个字典添加到主字典中的键?下面给出示例
- sql - ListAgg 和其他列选择
- git - 为什么 git fetch 在一些 rev-parse 命令后停止工作?
- php - laravel 7 包括外部类
- sql - 最近 X 天的累积非重复计数