Skip to content

Commit

Permalink
Improve example types
Browse files Browse the repository at this point in the history
  • Loading branch information
icflorescu committed Feb 29, 2024
1 parent d2813d1 commit 70800a3
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 6 deletions.
3 changes: 1 addition & 2 deletions examples/bookstall/src/lib/trpc/context.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { JWT_SECRET } from '$env/static/private';
import type { RequestEvent } from '@sveltejs/kit';
import type { inferAsyncReturnType } from '@trpc/server';
import jwt from 'jsonwebtoken';

export async function createContext(event: RequestEvent) {
Expand All @@ -17,4 +16,4 @@ export async function createContext(event: RequestEvent) {
}
}

export type Context = inferAsyncReturnType<typeof createContext>;
export type Context = Awaited<ReturnType<typeof createContext>>;
3 changes: 1 addition & 2 deletions examples/simple/src/lib/trpc/context.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import type { RequestEvent } from '@sveltejs/kit';
import type { inferAsyncReturnType } from '@trpc/server';

export async function createContext(event: RequestEvent) {
return {
event // 👈 `event` is now available in your context
};
}

export type Context = inferAsyncReturnType<typeof createContext>;
export type Context = Awaited<ReturnType<typeof createContext>>;
3 changes: 1 addition & 2 deletions examples/websocket/src/lib/trpc/context.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { inferAsyncReturnType } from '@trpc/server';
import type { CreateHTTPContextOptions } from '@trpc/server/adapters/standalone';
import type { CreateWSSContextFnOptions } from '@trpc/server/adapters/ws';

Expand All @@ -9,4 +8,4 @@ export async function createContext(opts: CreateHTTPContextOptions | CreateWSSCo
};
}

export type Context = inferAsyncReturnType<typeof createContext>;
export type Context = Awaited<ReturnType<typeof createContext>>;

0 comments on commit 70800a3

Please sign in to comment.