reactjs - typescript 错误不允许作为变量声明 name.ts

标签 reactjs typescript next.js

我正在使用 next.js 、react 和 typescript。
当我使用 switch 作为变量名时,出现 typescript 错误。
如何避免该错误?

'switch' is not allowed as a variable declaration name.ts(1389)
const Template: Story = (args: AtomSwitchProps) => <Switch {...args} />;

export const switch = Template.bind({});
switch.args = {
};

最佳答案

您不能在 JavaScript 程序中使用关键字作为标识符。 Switch 是一个保留关键字。保留关键字用于执行内部操作。 Here's JavaScript 关键字列表。

关于reactjs - typescript 错误不允许作为变量声明 name.ts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66915120/

相关文章:

angular - 选中复选框时更改标签样式 - Ionic 3

javascript - react : setting background image for a file present on the server

next.js - 如何仅在nextjs应用程序的一页中隐藏标题?

javascript - React 中更新对象数组中属性的更好方法

javascript - TypeScript 属性 'navigation' 类型中缺失,但类型 'Props' React Native 中需要

reactjs - Expo React Native 无法在 Android : "The system cannot find the path specified" 上启动项目

javascript - React-无法读取未定义的属性 'setState'

typescript - typescript 中的var和let有什么区别?

angular - 显示带有加载和错误情况的数据

reactjs - 使用 React 配置 Solidity 合约的最佳方法是什么?