prettier: TypeScript generics are removed incorrectly

Prettier 1.16.2 Playground link

--parser typescript

Input:

export default {
  load<K, T>(k: K, t: T) {
  	return {k, t};
  }
}

Output:

export default {
  load(k: K, t: T) {
    return { k, t };
  }
};

Expected behavior: preserve TypeScript generics

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 17 (11 by maintainers)

Commits related to this issue

Most upvoted comments

Oh wow, merging the PR on the other repo caused this issue to be closed. I’m guessing it piggybacked my permissions on both repos? Don’t think I’ve ever seen that before

No, it’s the same solution, but obviously want to avoid situations where multiple people are doing the same work

@j-f1 Did you not see this? https://github.com/prettier/prettier/issues/5817#issuecomment-459721349

I worked on this, just hadn’t opened a PR yet.

I found the AST oddity yesterday and @armano2 and I agreed that it shouldn’t be the case and we need to diverge from babel there (and report it)

I think we need merge test before close this to avoid regressions in future

The commit I proposed in PR #5989 should automatically close this issue as resolved and tested.

Thanks @evilebottnawi for your attention:)

This is because the parser puts the typeParamaters on the Property node rather than the FunctionExpression.

Thanks for pushing out a patch @ikatyang, I’m guessing we were just missing coverage for this in the prettier tests?

I can work on it and restore the updated version of typescript-estree