You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Error when using angle-bracket syntax in typescript. (e.g. const strLength: number = (<string>value).length;)
This is because @babel/plugin-transform-typescript has isTSX in its option.
in ./pages/index.vue?vue&type=script&setup=true&lang=ts (./node_modules/unplugin/dist/webpack/loaders/transform.js?unpluginName=nuxt%3Aimports-transform!./node_modules/unplugin/dist/webpack/loaders/transform.js?unpluginName=nuxt-legacy-vue-transform!./node_modules/babel-loader/lib??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./node_modules/unplugin/dist/webpack/loaders/transform.js?unpluginName=nuxt-legacy-capi-key-transform!./pages/index.vue?vue&type=script&setup=true&lang=ts)
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: /home/projects/github-qrwhz3/pages/index.vue: Unexpected token, expected "}" (10:14)
8 | const strLength: number = (<string>value).length;
9 |
> 10 | return { __sfc: true,value, strLength }
| ^
11 | }
12 |
13 | })
at constructor (file:///home/projects/github-qrwhz3/node_modules/@babel/parser/lib/index.js:356:19)
at TypeScriptParserMixin.raise (file:///home/projects/github-qrwhz3/node_modules/@babel/parser/lib/index.js:3223:19)
at TypeScriptParserMixin.unexpected (file:///home/projects/github-qrwhz3/node_modules/@babel/parser/lib/index.js:3253:16)
at TypeScriptParserMixin.expect (file:///home/projects/github-qrwhz3/node_modules/@babel/parser/lib/index.js:3585:28)
at TypeScriptParserMixin.jsxParseExpressionContainer (file:///home/projects/github-qrwhz3/node_modules/@babel/parser/lib/index.js:6797:10)
at TypeScriptParserMixin.jsxParseElementAt (file:///home/projects/github-qrwhz3/node_modules/@babel/parser/lib/index.js:6871:36)
at TypeScriptParserMixin.jsxParseElement (file:///home/projects/github-qrwhz3/node_modules/@babel/parser/lib/index.js:6915:17)
at TypeScriptParserMixin.parseExprAtom (file:///home/projects/github-qrwhz3/node_modules/@babel/parser/lib/index.js:6927:19)
at TypeScriptParserMixin.parseExprSubscripts (file:///home/projects/github-qrwhz3/node_modules/@babel/parser/lib/index.js:10857:23)
at TypeScriptParserMixin.parseUpdate (file:///home/projects/github-qrwhz3/node_modules/@babel/parser/lib/index.js:10840:21)
The workaround is to use as instead of angle-bracket syntax.
Additional context
No response
Logs
No response
The text was updated successfully, but these errors were encountered:
Environment
Reproduction
https://stackblitz.com/edit/github-qrwhz3
Describe the bug
Error when using angle-bracket syntax in typescript. (e.g.
const strLength: number = (<string>value).length;
)This is because
@babel/plugin-transform-typescript
hasisTSX
in its option.The workaround is to use
as
instead ofangle-bracket syntax
.Additional context
No response
Logs
No response
The text was updated successfully, but these errors were encountered: