Skip to content

Fix printing both index signatures without type annotations and multi-parameter index signatures#7228

Merged
lipis merged 9 commits intoprettier:masterfrom
cola119:issue/7225
Jan 8, 2020
Merged

Fix printing both index signatures without type annotations and multi-parameter index signatures#7228
lipis merged 9 commits intoprettier:masterfrom
cola119:issue/7225

Conversation

@cola119
Copy link
Copy Markdown
Contributor

@cola119 cola119 commented Jan 6, 2020

fixes #7225

  • I’ve added tests to confirm my change works.
  • (If changing the API or CLI) I’ve documented the changes I’ve made (in the docs/ directory)
  • (If the change is user-facing) I’ve added my changes to changelog_unreleased/*/pr-XXXX.md file following changelog_unreleased/TEMPLATE.md.
  • I’ve read the contributing guidelines.

Try the playground for this PR

@cola119
Copy link
Copy Markdown
Contributor Author

cola119 commented Jan 6, 2020

I guess I can fix #7224 quickly, but should I commit and push to this branch to avoid conflicts? Or is it better to create a new PR for that?

[key: string]: any;
}

type A = { [key: string] };
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an index signature without a type annotation is not valid TS, please move the test for this case to a separate file in tests/typescript_error_recovery.

@thorn0
Copy link
Copy Markdown
Member

thorn0 commented Jan 6, 2020

@cola119 I'd say it's okay to fix #7224 in this PR.

@cola119 cola119 changed the title Typescript: Remove unnecessary colons for TSIndexSignature without type parameters Fix printing both index signatures without type annotations and multi-parameter index signatures Jan 6, 2020
@cola119
Copy link
Copy Markdown
Contributor Author

cola119 commented Jan 6, 2020

@thorn0 thanks your reviews. I modified the pointed out items and fixed #7224.
Sorry in my poor English but please give me a review 🙇

Copy link
Copy Markdown
Contributor

@sosukesuzuki sosukesuzuki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the case it is long?

Playground

// Input
type T = {
  [loooooooooooooooooooooooooong: string, looooooooooooooooooooooooooooooooooooooong: string]: string;
}

// Output
type T = {
  [loooooooooooooooooooooooooong: string, looooooooooooooooooooooooooooooooooooooong: string]: string;
};

// Expected
type T = {
  [
    loooooooooooooooooooooooooong: string,
    looooooooooooooooooooooooooooooooooooooong: string
  ]: string;
};

Also, we should support trailing commas.

@cola119
Copy link
Copy Markdown
Contributor Author

cola119 commented Jan 7, 2020

@sosukesuzuki san,
I fixed to support long expressions and trailing comma. Please let me know if there are any problems.

Copy link
Copy Markdown
Contributor

@sosukesuzuki sosukesuzuki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@lipis lipis merged commit 5d165eb into prettier:master Jan 8, 2020
@cola119 cola119 deleted the issue/7225 branch January 9, 2020 01:14
@lock lock bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Apr 15, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Apr 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

typescript: TSIndexSignature without type parameters

4 participants