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
- @typescript-eslint/typescript-estree 1.4.2 resolves the issue with generics in object methods in TypeScript and passes the test proposed in the following PR: prettier/prettier#5824 resolves #5817 — committed to bangkokjs/prettierx-0.4.x-fork by deleted user 5 years ago
- Test generics in object methods in TypeScript as proposed by @j-f1 in the following PR: prettier/prettier#5824 should validate that #5817 does not reappear Co-authored-by: Jed Fox <git@twopointzero... — committed to bangkokjs/prettierx-0.4.x-fork by deleted user 5 years ago
- Test generics in object methods in TypeScript as proposed by @j-f1 in the following PR: prettier/prettier#5824 should validate that issue #5817 does not reappear closes #5817 as resolved and tested... — committed to bangkokjs/prettierx-0.4.x-fork by deleted user 5 years ago
- Test generics in object methods in TypeScript as proposed by @j-f1 in the following PR: prettier/prettier#5824 should validate that issue #5817 does not reappear this change closes #5817 as resolve... — committed to bangkokjs/prettierx-0.4.x-fork by deleted user 5 years ago
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)
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 theProperty
node rather than theFunctionExpression
.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