Skip to content

Allow trailing commas after non-rest elements in destructuring - #24672

Merged
Mohamed Hegazy (mhegazy) merged 1 commit into
microsoft:masterfrom
bakkot:binding-comma
Jun 6, 2018
Merged

Allow trailing commas after non-rest elements in destructuring#24672
Mohamed Hegazy (mhegazy) merged 1 commit into
microsoft:masterfrom
bakkot:binding-comma

Conversation

@bakkot

@bakkot Kevin Gibbons (bakkot) commented Jun 4, 2018

Copy link
Copy Markdown
Contributor

Fixes #24628.

cc Andy (Andrewkraft) (@Andy-MS) for the original change in #22262.

@msftclas

Microsoft Contribution License Agreements (msftclas) commented Jun 4, 2018

Copy link
Copy Markdown

CLA assistant check
All CLA requirements met.

@ghost ghost changed the title Allow trailing commas after-rest elements in destructuring Allow trailing commas after non-rest elements in destructuring Jun 4, 2018
@mhegazy
Mohamed Hegazy (mhegazy) merged commit 34dd773 into microsoft:master Jun 6, 2018
@mhegazy

Copy link
Copy Markdown
Contributor

thanks Kevin Gibbons (@bakkot)!

@bakkot
Kevin Gibbons (bakkot) deleted the binding-comma branch June 6, 2018 20:10
@swar30

Copy link
Copy Markdown

Will this be in 2.9.3 ?

@mhegazy

Copy link
Copy Markdown
Contributor

No. TS 3.0, should be out next week.

@JeromeLin

Copy link
Copy Markdown

This problem still exists in the 3.0.1

@ghost

Copy link
Copy Markdown

Jérôme Lipowicz (@jerome) The example from #24628 works for me with typescript@3.0.1, could you share example code that doesn't work for you?

@JeromeLin

Jerome (JeromeLin) commented Aug 16, 2018

Copy link
Copy Markdown

Andy (Andrewkraft) (@Andy-MS) in React component

import React, { PureComponent } from 'react';

export interface ButtonProps {
  size?: 'large' | 'normal' | 'small';
}

export default class Button extends PureComponent<ButtonProps, {}> {
  render() {
    const {
      size,
      children,
      ...others,     // error line
    } = this.props;
    return <a {...others}>{children}</a>;
  }
}

@bakkot

Copy link
Copy Markdown
Contributor Author

Jerome (@JeromeLin), that's not syntactically valid JavaScript or (as of #22262) TypeScript. You can't have a trailing comma after a rest element (...something) in a destructuring binding or assignment. This PR is specifically about commas after trailing non-rest elements.

TypeScript's behavior is correct; you should remove that comma.

@JeromeLin

Copy link
Copy Markdown

Kevin Gibbons (@bakkot) thanks. this problem has been solved.
I remove that comma,and add esSpecCompliant option in tslint config.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants