(12.0.0, SWC) TypeScript generics in objects incorrectly parsed as JSX
See original GitHub issueWhat 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:
- Created 2 years ago
- Reactions:6
- Comments:6 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I have a
.ts
file with angle-bracket syntax type assertion and getting theExpected 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.You can us "as comst " instead of " <const> " your project code