Type cast in useMemo () => ({} as Type) cause vite:esbuild transform error.
code:
const v = useMemo(
() =>
({
name: 'random',
age: count,
} as RandomType), // type cast here will cause error
[count]
);
// if not cast to `RandomType` in `()` return , its ok
const v2 = useMemo<RandomType>(
() => ({
name: 'random',
age: count,
}),
[count]
);
error msg:
10:34:53 [vite] hmr update /src/App.tsx
10:34:53 [vite] Internal server error: Transform failed with 1 error:
/home/projects/vitejs-vite-l8ggg5/src/App.tsx:17:9: ERROR: Expected ";" but found ":"
Plugin: vite:esbuild
File: /home/projects/vitejs-vite-l8ggg5/src/App.tsx:17:11
Expected ";" but found ":"
15 | {
16 | name: 'random',
17 | age: count
| ^
18 | } as RandomType, // type cast here will cause error
19 | [count]
at failureErrorWithLog (/home/projects/vitejs-vite-l8ggg5/node_modules/esbuild/lib/main.js:1462:15)
at eval (/home/projects/vitejs-vite-l8ggg5/node_modules/esbuild/lib/main.js:745:50)
at responseCallbacks.<computed> (/home/projects/vitejs-vite-l8ggg5/node_modules/esbuild/lib/main.js:612:9)
at handleIncomingPacket (/home/projects/vitejs-vite-l8ggg5/node_modules/esbuild/lib/main.js:667:12)
at Socket.readFromStdout (/home/projects/vitejs-vite-l8ggg5/node_modules/esbuild/lib/main.js:590:7)
at Socket.emit (node:events:30:10899)
at addChunk (node:internal/streams/readable:225:3685)
at readableAddChunk (node:internal/streams/readable:225:3393)
at Readable.push (node:internal/streams/readable:225:4971)
at _0x8d40b9.onStreamRead (node:internal/stream_base_commons:211:2596)
similar code like below doesn't cause error in vanilla vite, but errors with this plugin
Describe the bug
Type cast in useMemo
() => ({} as Type)
cause vite:esbuild transform error.code:
error msg:
similar code like below doesn't cause error in vanilla vite, but errors with this plugin
Reproduction
https://stackblitz.com/edit/vitejs-vite-l8ggg5?file=src%2FApp.tsx
Steps to reproduce
Run
npm install
thennpm run dev
System Info
Used Package Manager
npm
Logs
No response
Validations