-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
parent
in load functions receive @typescript-eslint/unbound-method
error
#12622
Comments
This also applies to other functions, such as Just posting the relevant details here, as it is the exact same issue as the OP is describing. Describe the bugWhen destructuring a function out of a function argument, for example like this: // `resolve` is a function that is destructured out of the function argument
async function handle({ event, resolve }) {
// ...
} ESLint yells at me:
Destructuing the function argument is very common, and is the way it's done in both the Docs and Tutorial for the handle hook. I don't think export type Handle = (input: {
event: RequestEvent;
resolve: (event: RequestEvent, opts?: ResolveOptions) => MaybePromise<Response>;
}) => MaybePromise<Response>; or this (annotating export type Handle = (input: {
event: RequestEvent;
resolve(this: void, event: RequestEvent, opts?: ResolveOptions): MaybePromise<Response>;
}) => MaybePromise<Response>; instead of this ( export type Handle = (input: {
event: RequestEvent;
resolve(event: RequestEvent, opts?: ResolveOptions): MaybePromise<Response>;
}) => MaybePromise<Response>; Note: The same issue applies to some other functions. At least ReproductionSet up SvelteKit with ESLint and Set up a handle hook: // src/hooks.server.js
import type { Handle } from "@sveltejs/kit";
export const handle: Handle = async ({ event, resolve }) => {
return await resolve(event);
} |
This is strange because those functions are arrow functions although it reports otherwise. Adding the |
Strange indeed! I also did a little test making changes to |
Any idea who might be able to look into this, @eltigerchino? |
Not at the moment. The team is still busy with the post-launch of Svelte 5. |
Enable the [ESLint `@typescript-eslint/unbound-method-error` rule][1] and fix/ignore all the errors it throws at us. Basically, this rule warns us from unbinding a function (e.g. doing `const {x} = {x() { /* etc */}}` that doesn't explicitly have `this: void`. I've replaced these types with arrow functions when possible, to avoid users of the SvelteKit library from facing the same ESLint issues. I've also manually fixed some types in `packages/kit/src/exports/public.d.ts` that weren't caught by the `@typescript-eslint/unbound-method-error` rule, since they're only destructured in `packages/kit/test/apps`, which is ignored by our ESLint config. However, this manual change should fix sveltejs#12622. [1]: https://typescript-eslint.io/rules/unbound-method/ Fix: sveltejs#12622
Describe the bug
My
+page.ts
looks like something like this:However, eslint seems not very happy about the
parent
function reference and throwsDocs on
unbound-method
Reproduction
MRE on Stackblitz
Run
pnpm eslint ./src
to see the errors.Logs
System Info
Severity
annoyance
Additional Information
Patrick in the server mentioned that perhaps
kit/packages/kit/types/index.d.ts
Lines 776 to 782 in 45cb8c5
and
kit/packages/kit/types/index.d.ts
Lines 1201 to 1206 in 45cb8c5
needs to be changed to
parent(this: void): Promise<ParentData>;
orparent: () => Promise<ParentData>;
, but it seems like this file is auto-generated…The text was updated successfully, but these errors were encountered: