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

fix(remix-dev): do not interpret JSX in .ts files #7306

Merged
merged 1 commit into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .changeset/gorgeous-carrots-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
"@remix-run/dev": patch
---

Do not interpret JSX in .ts files

While JSX is supported in `.js` files for compatibility with existing apps and libraries,
`.ts` files should not contain JSX. By not interpreting `.ts` files as JSX, `.ts` files
can contain single-argument type generics without needing a comma to disambiguate from JSX:

```ts
// this works in .ts files

const id = <T>(x: T) => x;
// ^ single-argument type generic
```

```tsx
// this doesn't work in .tsx files

const id = <T>(x: T) => x;
// ^ is this a JSX element? or a single-argument type generic?
```

```tsx
// this works in .tsx files

const id = <T,>(x: T) => x;
// ^ comma: this is a generic, not a JSX element

const component = <h1>hello</h1>
// ^ no comma: this is a JSX element
```
2 changes: 1 addition & 1 deletion packages/remix-dev/compiler/js/plugins/hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ declare global {
sourceCode,
output: {
contents: resultCode,
loader: "tsx",
loader: args.path.endsWith(".ts") ? "ts" : "tsx",
resolveDir: path.dirname(args.path),
},
};
Expand Down