Closed
Description
Describe the bug
My +page.ts
looks like something like this:
export const load: PageLoad = async ({ fetch, parent }) => {
const { uid } = (await parent()).session?.user ?? {};
if (!uid) {
throw new TypeError("User ID not found");
}
// Do something
};
However, eslint seems not very happy about the parent
function reference and throws
Avoid referencing unbound methods which may cause unintentional scoping of `this`.
If your function does not access `this`, you can annotate it with `this: void`, or consider using an arrow function instead. eslint(@typescript-eslint/unbound-method)
Reproduction
Run pnpm eslint ./src
to see the errors.
Logs
/home/projects/stackblitz-starters-1y7qpk/src/routes/sum/+layout.ts
3:42 error Avoid referencing unbound methods which may cause unintentional scoping of `this`.
If your function does not access `this`, you can annotate it with `this: void`, or consider using an arrow function instead @typescript-eslint/unbound-method
/home/projects/stackblitz-starters-1y7qpk/src/routes/sum/+page.ts
3:40 error Avoid referencing unbound methods which may cause unintentional scoping of `this`.
If your function does not access `this`, you can annotate it with `this: void`, or consider using an arrow function instead @typescript-eslint/unbound-method
✖ 2 problems (2 errors, 0 warnings)
System Info
System:
OS: Linux 5.0 undefined
CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 0 Bytes / 0 Bytes
Shell: 1.0 - /bin/jsh
Binaries:
Node: 18.20.3 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 10.2.3 - /usr/local/bin/npm
pnpm: 8.15.6 - /usr/local/bin/pnpm
npmPackages:
@sveltejs/adapter-auto: ^3.0.0 => 3.2.4
@sveltejs/kit: ^2.0.0 => 2.5.25
@sveltejs/vite-plugin-svelte: ^3.0.0 => 3.1.2
svelte: ^4.2.7 => 4.2.19
vite: ^5.0.3 => 5.4.2
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>;
or parent: () => Promise<ParentData>;
, but it seems like this file is auto-generated…