1

I made a react app with create-react-app typescript template. I made a simple card component, and I tried to destructuring an object but i have the following error : enter image description here

this is my tsconfig file

{
  "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"]
}

1 Answer 1

1

default is a reserved keyword used in switch statements. 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.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks @Matthieu, it was a rookie mistake

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.