Skip to content

Commit

Permalink
do not interpret JSX in .ts files
Browse files Browse the repository at this point in the history
  • Loading branch information
pcattori committed Aug 30, 2023
1 parent 848c8ea commit 3ae11f6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
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

0 comments on commit 3ae11f6

Please sign in to comment.