Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A binding pattern without rest element can have a trailing comma #24628

Closed
ikatyang opened this issue Jun 3, 2018 · 9 comments
Closed

A binding pattern without rest element can have a trailing comma #24628

ikatyang opened this issue Jun 3, 2018 · 9 comments
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue Help Wanted You can do this

Comments

@ikatyang
Copy link
Contributor

ikatyang commented Jun 3, 2018

TypeScript Version: 2.9.1/3.0.0-dev.20180602

Search Terms:

  • trailing comma
  • binding pattern
  • A rest parameter or binding pattern may not have a trailing comma.

Code

declare const anything: any[];

let a;

[
  a,
] = anything;

let [
  b,
] = anything;

Expected behavior:
no error

Actual behavior:

test.ts:6:4 - error TS1013: A rest parameter or binding pattern may not have a trailing comma.

6   a,
     ~

Per ECMAScript Spec, the trailing comma is allowed in a binding pattern without rest element.

image

Playground Link:
link

Related Issues:

(from prettier/prettier#4624)

@mhegazy
Copy link
Contributor

mhegazy commented Jun 4, 2018

PRs welcomed.

@alexander-lamdan
Copy link

declare const anything: any[];

let a;

[
a
] = anything;

let [
b,
] = anything;

[23:31:52] Found 0 errors. Watching for file changes.

Correct me if i wrong

@mhegazy mhegazy closed this as completed Jun 4, 2018
@mhegazy
Copy link
Contributor

mhegazy commented Jun 4, 2018

thanks @alexandrLamdan1995

@bakkot
Copy link
Contributor

bakkot commented Jun 4, 2018

@mhegazy I'm still seeing this on master:

$ cat in.ts
let a; [a,] = <any>[];

$ git rev-parse --short HEAD
7eaa78846e

$ gulp local
[...]

$ node built/local/tsc.js in.ts
in.ts:1:10 - error TS1013: A rest parameter or binding pattern may not have a trailing comma.

1 let a; [a,] = <any>[];
           ~

Looks like this was introduced in #22262. I'll submit a PR in a moment here.

@tarhunakau
Copy link

Will anyone try to fix it? Windows update - crash + BSOD, skype update - crash, Typescript update - crash. Do you have testers for your own products? The worst QA in all over the world... And that is Microsoft.

@j-f1
Copy link

j-f1 commented Jun 5, 2018

It’ll be fixed by #24672 @BLRplex.

@tarhunakau
Copy link

@j-f1 Hope it will not reopened again in few days. Thanks

@mhegazy mhegazy modified the milestones: Community, TypeScript 3.0 Jun 6, 2018
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Jun 6, 2018
@oleg-codaio
Copy link

Can this fix make it into into an earlier release, e.g., 2.9.2? We use Prettier and either we have to rip out all trailing commas or upset the TS compiler to update to 2.9.

@oleg-codaio
Copy link

As a workaround for anyone who stumbles into this issue, you can just append // prettier-ignore to an offending line and Prettier will not add a trailing comma there to satisfy TS.

feuGeneA added a commit to feuGeneA/0x-monorepo that referenced this issue Jun 14, 2018
before this change, TypeScript compilation of the generated contract
wrapper was giving me the following errors:

$ abi-gen --abis 'build/contracts/*.json' --out build/types --template contract_templates/contract.handlebars --partials 'contract_templates/partials/*.handlebars'
Found 7 partial templates
Found 1 ABI files
Processing: Migrations...
Created: build/types/migrations.ts
$ tsc
build/types/migrations.ts(81,23): error TS1013: A rest parameter or binding pattern may not have a trailing comma.
build/types/migrations.ts(108,23): error TS1013: A rest parameter or binding pattern may not have a trailing comma.
build/types/migrations.ts(130,23): error TS1013: A rest parameter or binding pattern may not have a trailing comma.
build/types/migrations.ts(146,25): error TS1013: A rest parameter or binding pattern may not have a trailing comma.
build/types/migrations.ts(173,25): error TS1013: A rest parameter or binding pattern may not have a trailing comma.
build/types/migrations.ts(195,25): error TS1013: A rest parameter or binding pattern may not have a trailing comma.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Here is the generated code around the first error:

74:    public setCompleted = {
75:        async sendTransactionAsync(
76:            completed: BigNumber,
77:            txData: Partial<TxData> = {},
78:        ): Promise<string> {
79:            const self = this as any as MigrationsContract;
80:            const inputAbi = self._lookupAbi('setCompleted(uint256)').inputs;
81:            [completed,
82:    ] = BaseContract._formatABIDataItemList(inputAbi, [completed,
83:    ], BaseContract._bigNumberToString.bind(self));

All of the other errors are the same, a destructuring assignment with a
single element but with a trailing comma.

This is legal JavaScript but it is not allowed by the TypeScript
compiler, apparently per the bug described at
microsoft/TypeScript#24628 .

While awaiting the 3.0 version of TypeScript, it's a simple enough
change to have the template not append a trailing comma.
feuGeneA added a commit to feuGeneA/0x-monorepo that referenced this issue Jun 14, 2018
before this change, TypeScript compilation of the generated contract
wrapper was giving me the following errors:

$ abi-gen --abis 'build/contracts/*.json' --out build/types --template contract_templates/contract.handlebars --partials 'contract_templates/partials/*.handlebars'
Found 7 partial templates
Found 1 ABI files
Processing: Migrations...
Created: build/types/migrations.ts
$ tsc
build/types/migrations.ts(81,23): error TS1013: A rest parameter or binding pattern may not have a trailing comma.
build/types/migrations.ts(108,23): error TS1013: A rest parameter or binding pattern may not have a trailing comma.
build/types/migrations.ts(130,23): error TS1013: A rest parameter or binding pattern may not have a trailing comma.
build/types/migrations.ts(146,25): error TS1013: A rest parameter or binding pattern may not have a trailing comma.
build/types/migrations.ts(173,25): error TS1013: A rest parameter or binding pattern may not have a trailing comma.
build/types/migrations.ts(195,25): error TS1013: A rest parameter or binding pattern may not have a trailing comma.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Here is the generated code around the first error:

74:    public setCompleted = {
75:        async sendTransactionAsync(
76:            completed: BigNumber,
77:            txData: Partial<TxData> = {},
78:        ): Promise<string> {
79:            const self = this as any as MigrationsContract;
80:            const inputAbi = self._lookupAbi('setCompleted(uint256)').inputs;
81:            [completed,
82:    ] = BaseContract._formatABIDataItemList(inputAbi, [completed,
83:    ], BaseContract._bigNumberToString.bind(self));

All of the other errors are the same, a destructuring assignment with a
single element but with a trailing comma.

This is legal JavaScript but it is not allowed by the TypeScript
compiler, apparently per the bug described at
microsoft/TypeScript#24628 .

While awaiting the 3.0 version of TypeScript, it's a simple enough
change to have the template not append a trailing comma.
kachkaev added a commit to shd101wyy/crossnote that referenced this issue Jun 23, 2018
kachkaev added a commit to gicentre/mume-with-litvis that referenced this issue Jun 23, 2018
kachkaev added a commit to shd101wyy/crossnote that referenced this issue Jun 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

7 participants