declare const o;
const {
a,
...rest
} = o;
with tslint.json configuration:
{
"rules": {
"trailing-comma": [true, {"multiline": "always", "singleline": "never"}]
}
}
See it on Playground.
An error occurs, indicating a trailing comma is expected.
Latest TypeScript disallows a trailing comma after an object rest param in destructuring to align with ECMAScript. This TSLint behavior requires to apply changes to the code that will make it not compile.
This was raised before in #3147 & #3795. However, then it was only a question of aligning with JavaScript and a style preference. Now it's an actual bug.
Adding "esSpecCompliant": true to the rule's options object fixes this.
Should that be enabled by default?
Yes, I think so. That's how I work around it in my code but default settings shouldn't require invalid syntax.
TBH, barring the breaking changes issue, I think this option shouldn't even exist as it's no longer possible to be non-ES compliant anymore here. IIRC this option was added as some people wanted to write code in a syntax compatible with upstream ECMAScript. The TypeScript language tries to remain close to ES syntax, though, so eventually, this hole was closed.
Being able to set "esSpecCompliant": false is only relevant to users of older TypeScript versions.
esSpecCompliant: true is enabled in all the built-in configs, tslint:all, tslint:recommended, and tslint:latest, which I believe should be sufficient for most users. we can change the behavior of the rule to make esSpecCompliant: true the default behavior in v6.0
~Removing~ Ignoring the Type: Breaking Change label per #4811. Now accepting PRs!
TSLint is deprecated and no longer accepting pull requests other than security fixes. See #4534. โ ๏ธ
We recommend you instead use typescript-eslint to lint your TypeScript code with ESLint. โ
๐ It was a pleasure open sourcing with you!
๐ค Beep boop! ๐ TSLint is deprecated ๐ _(#4534)_ and you should switch to typescript-eslint! ๐ค
๐ This issue is being locked to prevent further unnecessary discussions. Thank you! ๐
Most helpful comment
Adding
"esSpecCompliant": trueto the rule's options object fixes this.Should that be enabled by default?