Repository navigation
Replies: 1 comment
|
The current I reproduced that inference with SvelteKit 2.70.3 and TypeScript 6.0.3. The relevant signature is in the If you want one remote endpoint, a small wrapper in an ordinary // users.ts — ordinary module, not users.remote.ts
import { createUser as createUserRemote } from './users.remote';
import type { CreateUser, User, RoleCode } from './types';
export async function createUser<R extends RoleCode>(
input: CreateUser<R>
): Promise<User<R>> {
const user = await createUserRemote(input);
if (user.role !== input.role) {
throw new Error('Unexpected role in createUser response');
}
return { ...user, role: input.role };
}That return expression works for the The trade-off is that this wrapper returns a plain promise: it doesn't expose the remote command's I type-checked both the broad result from I searched the open issues for remote-function generics and didn't find an exact match; that isn't a guarantee none exists. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Let's say I have users, which have different roles, like a
freeuser, or apremiumuser.In my system,
Useris indexed by its role, which allows for better type safety:Now, I want a remote function to create such a user.
I have a function that uses some endpoint to add the user to some database.
What's great about this function is: If I add a user with a specific role, the type system allows me to guarantee that the resulting User still has that role associated.
However, when I use
command, this guarantee goes out the window:Is there any way to preserve this type parameter
Rthrough the remote function? Is there an open issue for it?All reactions