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

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

Merged
merged 1 commit into from Jun 6, 2018

Conversation

bakkot
Copy link
Contributor

@bakkot bakkot commented Jun 4, 2018

Fixes #24628.

cc @andy-ms for the original change in #22262.

@msftclas
Copy link

msftclas commented Jun 4, 2018

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 mhegazy merged commit 34dd773 into microsoft:master Jun 6, 2018
@mhegazy
Copy link
Contributor

mhegazy commented Jun 6, 2018

thanks @bakkot!

@bakkot bakkot deleted the binding-comma branch June 6, 2018 20:10
@swar30
Copy link

swar30 commented Jul 5, 2018

Will this be in 2.9.3 ?

@mhegazy
Copy link
Contributor

mhegazy commented Jul 5, 2018

No. TS 3.0, should be out next week.

@JeromeLin
Copy link

This problem still exists in the 3.0.1

@ghost
Copy link

ghost commented Aug 15, 2018

@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
Copy link

JeromeLin commented Aug 16, 2018

@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
Contributor Author

bakkot commented Aug 16, 2018

@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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants