question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(12.0.0, SWC) TypeScript generics in objects incorrectly parsed as JSX

See original GitHub issue

What version of Next.js are you using?

12.0.0

What version of Node.js are you using?

14.18.1

What browser are you using?

Chrome

What operating system are you using?

Linux

How are you deploying your application?

Vercel

Describe the Bug

Using the new SWC minifier on Next 12, objects that have functions with TypeScript generics seem to incorrectly be parsed as JSX.

Expected Behavior

TypeScript generics in objects with functions as keys should be correctly parsed

To Reproduce

Given the following code

export const Client = {
  axios: Axios.create({ baseURL: "..." }),
  delete<T extends Object>(params: T) {
    return Client.axios.request(params);
  },
}

Results in the following error:

Error: error: Expected a semicolon
   
    |
162 |   delete<T extends Object>(
    |         ^

error: Expected ',', got '< (jsx tag start)'
   
    |
162 |   delete<T extends Object>(
    |         ^

Caused by:
    0: failed to process js file
    1: Syntax Error

However, the following works OK

export const Client = {
  delete: function<T extends Object>(params: T) {
    return Client.axios.request(params);
  },
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:6
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
ThewBearcommented, Oct 27, 2021

I have a .ts file with angle-bracket syntax type assertion and getting the Expected jsx identifier error in Next.js 12.0.1. It was working fine in Next.js 11. It should only give this error only in .tsx file.

1reaction
Derushcommented, Oct 27, 2021

You can us "as comst " instead of " <const> " your project code

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error when parsing generators combined with generics #1526
Parsing this code with swc gives following error: error: Unexpected token `jsx name (export)`. Expected this, import, async, function, ...
Read more >
React Typescript fails to compile with a Generic Component
Fresh installs work. This is turning out to be a problem with some of the packages installed and/or the eslint configuration. reactjs ...
Read more >
Next.js 12 Has Been Released - Morioh
As we announced at Next.js Conf, Next.js 12 is our biggest release ever: Rust Compiler: ~3x faster Fast Refresh and ~5x faster builds;...
Read more >
Command line utilities — list of Rust libraries/crates // Lib.rs
A tui-rs framework to build tui interfaces, inspired by React and Elm ... Command line tool parse and analyze RINEX data ... Commandline...
Read more >
NixOS - DistroWatch.com
NixOS is an independently developed GNU/Linux distribution that aims to improve the state of the art in system configuration management.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found