-
-
Notifications
You must be signed in to change notification settings - Fork 88
Labels
component/integrationWeb framework integrationWeb framework integrationhelp wantedExtra attention is neededExtra attention is neededtype/bugSomething isn't workingSomething isn't working
Description
The SvelteKit hook in @fedify/fedify/x/sveltekit has the type:
type RequestEvent = {
request: Request
}
type HookParams = {
event: RequestEvent
// ^ covariant
resolve: (event: RequestEvent) => Promise<Response>
// ^ contravariant
}
fedifyHook(...): (params: HookParams) => Promise<Response>Notice two points here:
- The
RequestEventtype is defined locally and is a subtype of the actual type in SvelteKit RequestEventis invariant in the type offedifyHook(...), so the type offedifyHook(...)is not a subtype nor a supertype ofHandle, the handler hook type in SvelteKit.
Indeed, TypeScript complains if you try to mark it as a Handle:
import { fedifyHook } from '@fedify/fedify/x/svelte'
import type { Handle } from '@sveltejs/kit'
const handleActivityPub = fedifyHook(federation, makeContextData) as Handle
// ^^^^^^^^^
// TS2352: Conversion of type '(params: HookParams) => Promise<Response>' to type
// 'Handle' may be a mistake because neither type sufficiently overlaps with the other.
// If this was intentional, convert the expression to 'unknown' first.I suppose the most straightforward way to solve this is to add @sveltejs/kit to devDependencies and then use the actual Handle type from there, something like:
import type { Handle, RequestEvent } from '@sveltejs/kit'
export function fedifyHook<TContextData>(
federation: Federation<TContextData>,
createContextData: (
event: RequestEvent,
) => TContextData | Promise<TContextData>,
): Handle {
return async ({ event, resolve }) => {
// -- snip --
};
}PS. I see the AI labeler adding more and more labels to my issue every time I edit it. You may want to fix that too!
Metadata
Metadata
Assignees
Labels
component/integrationWeb framework integrationWeb framework integrationhelp wantedExtra attention is neededExtra attention is neededtype/bugSomething isn't workingSomething isn't working