简体   繁体   English

当我尝试解构 object 时出现 typescript 错误

[英]typescript error when I tried to destructuring an object

I made a react app with create-react-app typescript template.我使用 create-react-app typescript 模板制作了一个反应应用程序。 I made a simple card component, and I tried to destructuring an object but i have the following error: enter image description here我制作了一个简单的卡片组件,并尝试解构 object 但出现以下错误:在此处输入图像描述

this is my tsconfig file这是我的 tsconfig 文件

 { "compilerOptions": { "target":"ES2020", "lib": [ "dom", "dom.iterable", "esnext" ], "allowJs": true, "skipLibCheck": true, "esModuleInterop": true, "allowSyntheticDefaultImports": true, "strict": true, "forceConsistentCasingInFileNames": true, "noFallthroughCasesInSwitch": true, "module":"ES2020", "moduleResolution": "node", "resolveJsonModule": true, "isolatedModules": true, "noEmit": true, "jsx": "react-jsx" }, "include": [ "src" ], "exclude": ["node_modules"] }

default is a reserved keyword used in switch statements. default是 switch 语句中使用的保留关键字。 Any other name will be fine.任何其他名称都可以。

interface CardProps {
    default: 'test';
    defaults: 'test';
}

declare const props: CardProps;

const { default } = props; // KO
const { defaults } = props; // OK

See other reserved keywords . 查看其他保留关键字

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Object 在 typescript 中解构 - Object destructuring in typescript 在使用默认值对空对象进行解构时,打字稿类型错误? - Typescript type error while destructuring on empty object with default values? 当我对 object 进行动态解构时,React 出现意外的令牌错误 - React comes back with an unexpected token error when I do a dynamic destructuring of my object TypeScript/React - 从 useContext 解构会引发错误 - TypeScript/React - destructuring from useContext throws an error 当我使用解构赋值来简化我的道具时出错 - getting error when I use destructuring assignment to simplify my props 如何解决 Error Use object destructuring prefer-destructuring - React - How to solve Error Use object destructuring prefer-destructuring - React 为什么与 Typescript 函数反应的解构道具需要传递一个对象? - Why does destructuring props in react with Typescript function require passing an object? Typescript useState React Hook 解构错误(不返回数组?) - Typescript useState React Hook Destructuring Error (Not Returning Array?) Typescript:解构 hash 时如何使用符号作为键 - Typescript: How to use a symbol as a key when destructuring a hash 在 TypeScript 中解构 React 钩子数组时,此表达式不可调用 - This expression is not callable when destructuring an array of React hooks in TypeScript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM