-
-
Notifications
You must be signed in to change notification settings - Fork 225
Closed
Labels
Description
Related plugins
Describe the bug
type A = {
register: (callback: unknown) => void;
};
const a = {
register: (callback: unknown) => {
console.log(callback);
},
};
export function Test() {
const funA = async <T,>(arg1: T) => {
console.log(arg1)
}
(a as A).register(funA);
return (
<div>
<h1>Test</h1>
</div>
);
}generated code:
const a = {
register: (callback) => {
console.log(callback);
}
};
export function Test() {
const funA = (async (arg1) => {
console.log(arg1);
})(
a
).register(funA);
return /* @__PURE__ */ jsxDEV("div", { children: /* @__PURE__ */ jsxDEV("h1", { children: "Test" }, void 0, false, {
fileName: "/project/workspace/src/Test.tsx",
lineNumber: 36,
columnNumber: 7
}, this) }, void 0, false, {
fileName: "/project/workspace/src/Test.tsx",
lineNumber: 35,
columnNumber: 5
}, this);
}Error: Uncaught ReferenceError: Cannot access 'funA' before initialization
at Test (Test.tsx:14:21)
Corrected code should be
const a = {
register: (callback) => {
console.log(callback);
}
};
export function Test() {
const funA = (async (arg1) => {
console.log(arg1);
});
a.register(funA);
return /* @__PURE__ */ jsxDEV("div", { children: /* @__PURE__ */ jsxDEV("h1", { children: "Test" }, void 0, false, {
fileName: "/project/workspace/src/Test.tsx",
lineNumber: 36,
columnNumber: 7
}, this) }, void 0, false, {
fileName: "/project/workspace/src/Test.tsx",
lineNumber: 35,
columnNumber: 5
}, this);
}If you add a semicolon at the end of the funA declaration, everything works fine.
const funA = async <T,>(arg1: T) => {
console.log(arg1)
};
(a as A).register(funA);Reproduction
Steps to reproduce
No response
System Info
codsandboxUsed Package Manager
npm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.