typescriptecmascript-6

How to fix "property destructuring pattern expected" error?


I'm getting this error:

vscode screenshot

Same error when I try to compile:

c:\...\tsx-test>ntsc app/main.tsx
app/components/Note.tsx(13,31): error TS1180: Property destructuring pattern expected.

But I don't know what it's expecting. What's the property syntax?

I'm pretty sure this works as-is in ES6. Is the syntax different in TypeScript?

Note that I'm using TypeScript 1.5.3.


Solution

  • I'm pretty sure this works as-is in ES6.

    the {a, b, ...rest} = props pattern is supported by TypeScript now. Just update to the latest compiler and it will work without error.

    More

    Some docs on the TypeScript destructuring:

    https://basarat.gitbook.io/typescript/type-system/type-inference#destructuring