Skip to content

Workaround for TSX/Generics ambiguity leads to non-typesafe transforms #274

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

Closed
joscha opened this issue Aug 27, 2021 · 0 comments
Closed
Labels
enhancement New feature or request

Comments

@joscha
Copy link
Contributor

joscha commented Aug 27, 2021

Describe the bug

There's a parsing ambiguity in TS, sometimes it doesn't know if <T> is JSX or a type parameter.
The recommendation is to give a TS a clue with <T extends any> or <T, >, see microsoft/TypeScript#15713.

dprint removes the additional comma, which makes TS think its the start of a JSX expression and thus it leads to a type error.

This only happens in .tsx files and could possibly be related to #265 (or not related at all, haha).

This bug is more than a simple formatting issue, as formatting breaks Typechecking/transpilation in this particular case.

dprint-plugin-typescript version: 0.51.0

Possible workaround

Change <T, > to <T extends any> which is formatted safely

Input Code

export const SelectRow = <T, >(row: Row<T>) => false;

Expected Output

export const SelectRow = <T, >(row: Row<T>) => false;

Actual Output

export const SelectRow = <T>(row: Row<T>) => false;

(bit hard to see, note the removal of , )

cc @WearyMonkey

@dsherret dsherret added the enhancement New feature or request label Aug 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants