Angular
@trpc12/tanstack-angular-query: provideTrpc() next to provideTanStackQuery, injectTrpc() in components, and injectSubscription with signals.
On this page
@trpc12/tanstack-angular-query re-exports @trpc12/tanstack-query and adds a provider and injectors for a client and its helpers, and an injectSubscription that returns signals. It's for @tanstack/angular-query-experimental.
pnpm add @trpc12/trpc @trpc12/tanstack-angular-query @tanstack/angular-query-experimentalnpm install @trpc12/trpc @trpc12/tanstack-angular-query @tanstack/angular-query-experimentalyarn add @trpc12/trpc @trpc12/tanstack-angular-query @tanstack/angular-query-experimentalbun add @trpc12/trpc @trpc12/tanstack-angular-query @tanstack/angular-query-experimentalProvide the client
createTrpcContext takes the type of the function that makes the client (or of the client, or the router), so the helpers get what its links declare. Add provideTrpc(client) next to provideTanStackQuery:
// trpc.ts
const const makeClient: () => TrpcClient<{
post: {
byId: BuildProcedure<InputDef<RootDef<Context, {}>, ZodObject<{
id: ZodString;
}, $strip>>, "query", {
output: Post;
errors: TrpcError<"NOT_FOUND", {
id: string;
}>;
services: never;
unmapped: never;
}>;
list: BuildProcedure<RootDef<Context, {}>, "query", {
output: Post[];
errors: never;
services: never;
unmapped: never;
}>;
create: BuildProcedure<InputDef<With<RootDef<Context, {}>, {
ctx: Context;
ctxAdded: {
...;
};
inputOut: Unset;
errors: TrpcError<...>;
shorts: never;
}>, ZodObject<...>>, "mutation", {
...;
}>;
};
}, {}, undefined, LinksTypes<...>>
makeClient = () =>
createTrpcClient<RouterType<{
post: {
byId: BuildProcedure<InputDef<RootDef<Context, {}>, ZodObject<{
id: ZodString;
}, $strip>>, "query", {
output: Post;
errors: TrpcError<"NOT_FOUND", {
id: string;
}>;
services: never;
unmapped: never;
}>;
list: BuildProcedure<RootDef<Context, {}>, "query", {
output: Post[];
errors: never;
services: never;
unmapped: never;
}>;
create: BuildProcedure<InputDef<With<RootDef<Context, {}>, {
ctx: Context;
ctxAdded: {
...;
};
inputOut: Unset;
errors: TrpcError<...>;
shorts: never;
}>, ZodObject<...>>, "mutation", {
...;
}>;
};
}>, readonly [...]>(opts: TypedClientOptions<...>): TrpcClient<...>
createTrpcClient({
TypedClientOptions<RouterType<{ post: { byId: BuildProcedure<InputDef<RootDef<Context, {}>, ZodObject<{ id: ZodString; }, $strip>>, "query", { output: Post; errors: TrpcError<...>; services: never; unmapped: never; }>; list: BuildProcedure<...>; create: BuildProcedure<...>; }; }>, readonly [...]>.router: RouterType<{
post: {
byId: BuildProcedure<InputDef<RootDef<Context, {}>, ZodObject<{
id: ZodString;
}, $strip>>, "query", {
output: Post;
errors: TrpcError<"NOT_FOUND", {
id: string;
}>;
services: never;
unmapped: never;
}>;
list: BuildProcedure<RootDef<Context, {}>, "query", {
output: Post[];
errors: never;
services: never;
unmapped: never;
}>;
create: BuildProcedure<InputDef<With<RootDef<Context, {}>, {
ctx: Context;
ctxAdded: {
...;
};
inputOut: Unset;
errors: TrpcError<...>;
shorts: never;
}>, ZodObject<...>>, "mutation", {
...;
}>;
};
}>
router: routerType<{
post: {
byId: BuildProcedure<InputDef<RootDef<Context, {}>, ZodObject<{
id: ZodString;
}, $strip>>, "query", {
output: Post;
errors: TrpcError<"NOT_FOUND", {
id: string;
}>;
services: never;
unmapped: never;
}>;
list: BuildProcedure<RootDef<Context, {}>, "query", {
output: Post[];
errors: never;
services: never;
unmapped: never;
}>;
create: BuildProcedure<InputDef<With<RootDef<Context, {}>, {
ctx: Context;
ctxAdded: {
...;
};
inputOut: Unset;
errors: TrpcError<...>;
shorts: never;
}>, ZodObject<...>>, "mutation", {
...;
}>;
};
}>(): RouterType<...>
routerType<type AppRouter = {
post: {
byId: BuildProcedure<InputDef<RootDef<Context, {}>, ZodObject<{
id: ZodString;
}, $strip>>, "query", {
output: Post;
errors: TrpcError<"NOT_FOUND", {
id: string;
}>;
services: never;
unmapped: never;
}>;
list: BuildProcedure<RootDef<Context, {}>, "query", {
output: Post[];
errors: never;
services: never;
unmapped: never;
}>;
create: BuildProcedure<InputDef<With<RootDef<Context, {}>, {
ctx: Context;
ctxAdded: {
...;
};
inputOut: Unset;
errors: TrpcError<...>;
shorts: never;
}>, ZodObject<...>>, "mutation", {
...;
}>;
};
}
AppRouter>(),
TypedClientOptions<RouterType<{ post: { byId: BuildProcedure<InputDef<RootDef<Context, {}>, ZodObject<{ id: ZodString; }, $strip>>, "query", { output: Post; errors: TrpcError<...>; services: never; unmapped: never; }>; list: BuildProcedure<...>; create: BuildProcedure<...>; }; }>, readonly [...]>.links: readonly [TrpcLink<{
form: JsonForm;
provides: "response";
}, any>]
links: [httpLink<{
url: string;
}>(opts: {
url: string;
}): TrpcLink<{
form: JsonForm;
provides: "response";
}, any>
httpLink({ url: stringurl: '/trpc' })],
});
export const { const provideTrpc: (client: TrpcClient<{
post: {
byId: BuildProcedure<InputDef<RootDef<Context, {}>, ZodObject<{
id: ZodString;
}, $strip>>, "query", {
output: Post;
errors: TrpcError<"NOT_FOUND", {
id: string;
}>;
services: never;
unmapped: never;
}>;
list: BuildProcedure<RootDef<Context, {}>, "query", {
output: Post[];
errors: never;
services: never;
unmapped: never;
}>;
create: BuildProcedure<InputDef<With<RootDef<Context, {}>, {
ctx: Context;
ctxAdded: {
...;
};
inputOut: Unset;
errors: TrpcError<...>;
shorts: never;
}>, ZodObject<...>>, "mutation", {
...;
}>;
};
}, {}, undefined, LinksTypes<...>>) => Provider
provideTrpc, const injectTrpc: () => TrpcQueryUtilsFor<{
post: {
byId: BuildProcedure<InputDef<RootDef<Context, {}>, ZodObject<{
id: ZodString;
}, $strip>>, "query", {
output: Post;
errors: TrpcError<"NOT_FOUND", {
id: string;
}>;
services: never;
unmapped: never;
}>;
list: BuildProcedure<RootDef<Context, {}>, "query", {
output: Post[];
errors: never;
services: never;
unmapped: never;
}>;
create: BuildProcedure<InputDef<With<RootDef<Context, {}>, {
ctx: Context;
ctxAdded: {
...;
};
inputOut: Unset;
errors: TrpcError<...>;
shorts: never;
}>, ZodObject<...>>, "mutation", {
...;
}>;
};
}, {}, LinksTypes<...>>
injectTrpc, const injectTrpcClient: () => TrpcClient<{
post: {
byId: BuildProcedure<InputDef<RootDef<Context, {}>, ZodObject<{
id: ZodString;
}, $strip>>, "query", {
output: Post;
errors: TrpcError<"NOT_FOUND", {
id: string;
}>;
services: never;
unmapped: never;
}>;
list: BuildProcedure<RootDef<Context, {}>, "query", {
output: Post[];
errors: never;
services: never;
unmapped: never;
}>;
create: BuildProcedure<InputDef<With<RootDef<Context, {}>, {
ctx: Context;
ctxAdded: {
...;
};
inputOut: Unset;
errors: TrpcError<...>;
shorts: never;
}>, ZodObject<...>>, "mutation", {
...;
}>;
};
}, {}, undefined, LinksTypes<...>>
injectTrpcClient } =
createTrpcContext<() => TrpcClient<{
post: {
byId: BuildProcedure<InputDef<RootDef<Context, {}>, ZodObject<{
id: ZodString;
}, $strip>>, "query", {
output: Post;
errors: TrpcError<"NOT_FOUND", {
id: string;
}>;
services: never;
unmapped: never;
}>;
list: BuildProcedure<RootDef<Context, {}>, "query", {
output: Post[];
errors: never;
services: never;
unmapped: never;
}>;
create: BuildProcedure<InputDef<With<RootDef<Context, {}>, {
ctx: Context;
ctxAdded: {
...;
};
inputOut: Unset;
errors: TrpcError<...>;
shorts: never;
}>, ZodObject<...>>, "mutation", {
...;
}>;
};
}, {}, undefined, LinksTypes<...>>>(opts?: TrpcContextOptions): TrpcAngularContext<...>
createTrpcContext<typeof const makeClient: () => TrpcClient<{
post: {
byId: BuildProcedure<InputDef<RootDef<Context, {}>, ZodObject<{
id: ZodString;
}, $strip>>, "query", {
output: Post;
errors: TrpcError<"NOT_FOUND", {
id: string;
}>;
services: never;
unmapped: never;
}>;
list: BuildProcedure<RootDef<Context, {}>, "query", {
output: Post[];
errors: never;
services: never;
unmapped: never;
}>;
create: BuildProcedure<InputDef<With<RootDef<Context, {}>, {
ctx: Context;
ctxAdded: {
...;
};
inputOut: Unset;
errors: TrpcError<...>;
shorts: never;
}>, ZodObject<...>>, "mutation", {
...;
}>;
};
}, {}, undefined, LinksTypes<...>>
makeClient>();
// main.ts
function bootstrapApplication(rootComponent: Type<unknown>, options?: ApplicationConfig, context?: BootstrapContext): Promise<ApplicationRef>bootstrapApplication(class AppApp, {
ApplicationConfig.providers: (Provider | EnvironmentProviders)[]providers: [
function provideTanStackQuery(queryClient: QueryClient | InjectionToken<QueryClient>, ...features: Array<QueryFeatures>): Array<Provider>provideTanStackQuery(new new QueryClient(config?: QueryClientConfig): QueryClientQueryClient()),
const provideTrpc: (client: TrpcClient<{
post: {
byId: BuildProcedure<InputDef<RootDef<Context, {}>, ZodObject<{
id: ZodString;
}, $strip>>, "query", {
output: Post;
errors: TrpcError<"NOT_FOUND", {
id: string;
}>;
services: never;
unmapped: never;
}>;
list: BuildProcedure<RootDef<Context, {}>, "query", {
output: Post[];
errors: never;
services: never;
unmapped: never;
}>;
create: BuildProcedure<InputDef<With<RootDef<Context, {}>, {
ctx: Context;
ctxAdded: {
...;
};
inputOut: Unset;
errors: TrpcError<...>;
shorts: never;
}>, ZodObject<...>>, "mutation", {
...;
}>;
};
}, {}, undefined, LinksTypes<...>>) => Provider
provideTrpc(const makeClient: () => TrpcClient<{
post: {
byId: BuildProcedure<InputDef<RootDef<Context, {}>, ZodObject<{
id: ZodString;
}, $strip>>, "query", {
output: Post;
errors: TrpcError<"NOT_FOUND", {
id: string;
}>;
services: never;
unmapped: never;
}>;
list: BuildProcedure<RootDef<Context, {}>, "query", {
output: Post[];
errors: never;
services: never;
unmapped: never;
}>;
create: BuildProcedure<InputDef<With<RootDef<Context, {}>, {
ctx: Context;
ctxAdded: {
...;
};
inputOut: Unset;
errors: TrpcError<...>;
shorts: never;
}>, ZodObject<...>>, "mutation", {
...;
}>;
};
}, {}, undefined, LinksTypes<...>>
makeClient()),
],
});injectTrpcClient() returns the client itself, for calls outside TanStack Query.
Queries and mutations
Call injectTrpc() in an injection context (a field initializer) and pass a function to injectQuery, so the options follow signals; a new input is a new key:
@function Component(obj: Component): TypeDecoratorComponent({
Directive.selector?: string | undefinedselector: 'app-post',
Component.template?: string | undefinedtemplate: `
<h1>{{ post.data()?.title }}</h1>
<button (click)="create.mutate({ title: 'New' })">New post</button>
`,
})
export class class PostComponentPostComponent {
PostComponent.trpc: TrpcQueryUtilsFor<{
post: {
byId: BuildProcedure<InputDef<RootDef<Context, {}>, ZodObject<{
id: ZodString;
}, $strip>>, "query", {
output: Post;
errors: TrpcError<"NOT_FOUND", {
id: string;
}>;
services: never;
unmapped: never;
}>;
list: BuildProcedure<RootDef<Context, {}>, "query", {
output: Post[];
errors: never;
services: never;
unmapped: never;
}>;
create: BuildProcedure<InputDef<With<RootDef<Context, {}>, {
ctx: Context;
ctxAdded: {
...;
};
inputOut: Unset;
errors: TrpcError<...>;
shorts: never;
}>, ZodObject<...>>, "mutation", {
...;
}>;
};
}, {}, {}>
trpc = const injectTrpc: () => TrpcQueryUtilsFor<{
post: {
byId: BuildProcedure<InputDef<RootDef<Context, {}>, ZodObject<{
id: ZodString;
}, $strip>>, "query", {
output: Post;
errors: TrpcError<"NOT_FOUND", {
id: string;
}>;
services: never;
unmapped: never;
}>;
list: BuildProcedure<RootDef<Context, {}>, "query", {
output: Post[];
errors: never;
services: never;
unmapped: never;
}>;
create: BuildProcedure<InputDef<With<RootDef<Context, {}>, {
ctx: Context;
ctxAdded: {
...;
};
inputOut: Unset;
errors: TrpcError<...>;
shorts: never;
}>, ZodObject<...>>, "mutation", {
...;
}>;
};
}, {}, {}>
injectTrpc();
PostComponent.queryClient: QueryClientqueryClient = inject<QueryClient>(token: ProviderToken<QueryClient>): QueryClient (+5 overloads)inject(class QueryClientQueryClient);
PostComponent.id: InputSignal<string>id = const input: InputFunctioninput.InputFunction.required: <string>(opts?: InputOptionsWithoutTransform<string> | undefined) => InputSignal<string> (+1 overload)required<string>();
PostComponent.post: CreateQueryResult<{
id: string;
title: string;
author: string | null;
createdAt: string;
}, NonNullable<UnexpectedError | (TrpcError<"NOT_FOUND", {
id: string;
}> & {
readonly defined: true;
}) | (TrpcError<"BAD_REQUEST", InputValidationErrorData<{
readonly code: "invalid_type";
readonly expected: $ZodInvalidTypeExpected;
readonly path: readonly [] | readonly ["id"];
readonly message: string;
} | {
readonly code: "too_big";
readonly origin: "number" | "int" | "bigint" | "date" | "string" | "array" | "set" | "file" | (string & {});
... 4 more ...;
readonly message: string;
} | ... 9 more ... | {
...;
}>> & {
...;
})>>
post = injectQuery<{
id: string;
title: string;
author: string | null;
createdAt: string;
}, NonNullable<UnexpectedError | (TrpcError<"NOT_FOUND", {
id: string;
}> & {
readonly defined: true;
}) | (TrpcError<"BAD_REQUEST", InputValidationErrorData<{
readonly code: "invalid_type";
readonly expected: $ZodInvalidTypeExpected;
readonly path: readonly [] | readonly ["id"];
readonly message: string;
} | {
readonly code: "too_big";
readonly origin: "number" | "int" | "bigint" | "date" | "string" | "array" | "set" | "file" | (string & {});
... 4 more ...;
readonly message: string;
} | ... 9 more ... | {
...;
}>> & {
...;
})>, {
id: string;
title: string;
author: string | null;
createdAt: string;
}, TrpcQueryKey & {
...;
}>(injectQueryFn: () => UndefinedInitialDataOptions<...>, options?: InjectQueryOptions): CreateQueryResult<...> (+2 overloads)
injectQuery(() =>
this.PostComponent.trpc: TrpcQueryUtilsFor<{
post: {
byId: BuildProcedure<InputDef<RootDef<Context, {}>, ZodObject<{
id: ZodString;
}, $strip>>, "query", {
output: Post;
errors: TrpcError<"NOT_FOUND", {
id: string;
}>;
services: never;
unmapped: never;
}>;
list: BuildProcedure<RootDef<Context, {}>, "query", {
output: Post[];
errors: never;
services: never;
unmapped: never;
}>;
create: BuildProcedure<InputDef<With<RootDef<Context, {}>, {
ctx: Context;
ctxAdded: {
...;
};
inputOut: Unset;
errors: TrpcError<...>;
shorts: never;
}>, ZodObject<...>>, "mutation", {
...;
}>;
};
}, {}, {}>
trpc.post: TrpcQueryUtils<ClientRouter<{
byId: BuildProcedure<InputDef<RootDef<Context, {}>, ZodObject<{
id: ZodString;
}, $strip>>, "query", {
output: Post;
errors: TrpcError<"NOT_FOUND", {
id: string;
}>;
services: never;
unmapped: never;
}>;
list: BuildProcedure<RootDef<Context, {}>, "query", {
output: Post[];
errors: never;
services: never;
unmapped: never;
}>;
create: BuildProcedure<InputDef<With<RootDef<Context, {}>, {
ctx: Context;
ctxAdded: {
...;
};
inputOut: Unset;
errors: TrpcError<...>;
shorts: never;
}>, ZodObject<...>>, "mutation", {
...;
}>;
}, {}, undefined, {}>>
post.byId: QueryProcedureUtils<{
id: string;
}, {
id: string;
title: string;
author: string | null;
createdAt: string;
}, NonNullable<UnexpectedError | (TrpcError<"NOT_FOUND", {
id: string;
}> & {
readonly defined: true;
}) | (TrpcError<"BAD_REQUEST", InputValidationErrorData<{
readonly code: "invalid_type";
readonly expected: $ZodInvalidTypeExpected;
readonly path: readonly [] | readonly ["id"];
readonly message: string;
} | {
readonly code: "too_big";
readonly origin: "number" | "int" | "bigint" | "date" | "string" | "array" | "set" | "file" | (string & {});
... 4 more ...;
readonly message: string;
} | ... 9 more ... | {
...;
}>> & {
...;
})>, Omit<...>>
byId.QueryProcedureUtils<{ id: string; }, { id: string; title: string; author: string | null; createdAt: string; }, NonNullable<UnexpectedError | (TrpcError<"NOT_FOUND", { id: string; }> & { ...; }) | (TrpcError<...> & { ...; })>, Omit<...>>.queryOptions<{
id: string;
title: string;
author: string | null;
createdAt: string;
}>(opts: {
input: {
id: string;
} | unique symbol;
} & ContextBag<Omit<NonNullable<{
signal?: AbortSignal | undefined;
} & BuiltinCallOptions>, "signal" | "lastEventId">> & QueryOptionsIn<{
id: string;
title: string;
author: string | null;
createdAt: string;
}, NonNullable<UnexpectedError | (TrpcError<"NOT_FOUND", {
id: string;
}> & {
readonly defined: true;
}) | (TrpcError<"BAD_REQUEST", InputValidationErrorData<{
readonly code: "invalid_type";
readonly expected: $ZodInvalidTypeExpected;
readonly path: readonly [] | readonly [...];
readonly message: string;
} | ... 10 more ... | {
...;
}>> & {
...;
})>, {
id: string;
title: string;
author: string | null;
createdAt: string;
}>): QueryOptionsOut<...> (+1 overload)
queryOptions({ input: {
id: string;
} | unique symbol
input: { id: stringid: this.PostComponent.id: InputSignal
() => string
id() } }),
);
PostComponent.create: CreateMutationResult<{
id: string;
title: string;
author: string | null;
createdAt: string;
}, (TrpcError<"NOT_FOUND" | "BAD_REQUEST" | "UNAUTHORIZED" | "PARSE_ERROR" | "UNSUPPORTED_PROTOCOL" | "PAYMENT_REQUIRED" | "FORBIDDEN" | "METHOD_NOT_SUPPORTED" | "TIMEOUT" | "CONFLICT" | "PRECONDITION_FAILED" | "PAYLOAD_TOO_LARGE" | "UNSUPPORTED_MEDIA_TYPE" | "UNPROCESSABLE_CONTENT" | "TOO_MANY_REQUESTS" | "CLIENT_CLOSED_REQUEST" | "INTERNAL_SERVER_ERROR" | "NOT_IMPLEMENTED" | "BAD_GATEWAY" | "SERVICE_UNAVAILABLE" | "GATEWAY_TIMEOUT" | "NETWORK_ERROR" | "CLIENT_ERROR" | "STREAM_INTERRUPTED" | (string & {}), unknown> & {
...;
}) | (TrpcError<...> & {
...;
}) | (TrpcError<...> & {
...;
}), {
...;
}, undefined>
create = injectMutation<{
id: string;
title: string;
author: string | null;
createdAt: string;
}, (TrpcError<"NOT_FOUND" | "BAD_REQUEST" | "UNAUTHORIZED" | "PARSE_ERROR" | "UNSUPPORTED_PROTOCOL" | "PAYMENT_REQUIRED" | "FORBIDDEN" | "METHOD_NOT_SUPPORTED" | "TIMEOUT" | "CONFLICT" | "PRECONDITION_FAILED" | "PAYLOAD_TOO_LARGE" | "UNSUPPORTED_MEDIA_TYPE" | "UNPROCESSABLE_CONTENT" | "TOO_MANY_REQUESTS" | "CLIENT_CLOSED_REQUEST" | "INTERNAL_SERVER_ERROR" | "NOT_IMPLEMENTED" | "BAD_GATEWAY" | "SERVICE_UNAVAILABLE" | "GATEWAY_TIMEOUT" | "NETWORK_ERROR" | "CLIENT_ERROR" | "STREAM_INTERRUPTED" | (string & {}), unknown> & {
...;
}) | (TrpcError<...> & {
...;
}) | (TrpcError<...> & {
...;
}), {
...;
}, undefined>(injectMutationFn: () => CreateMutationOptions<...>, options?: InjectMutationOptions): CreateMutationResult<...>
injectMutation(() =>
this.PostComponent.trpc: TrpcQueryUtilsFor<{
post: {
byId: BuildProcedure<InputDef<RootDef<Context, {}>, ZodObject<{
id: ZodString;
}, $strip>>, "query", {
output: Post;
errors: TrpcError<"NOT_FOUND", {
id: string;
}>;
services: never;
unmapped: never;
}>;
list: BuildProcedure<RootDef<Context, {}>, "query", {
output: Post[];
errors: never;
services: never;
unmapped: never;
}>;
create: BuildProcedure<InputDef<With<RootDef<Context, {}>, {
ctx: Context;
ctxAdded: {
...;
};
inputOut: Unset;
errors: TrpcError<...>;
shorts: never;
}>, ZodObject<...>>, "mutation", {
...;
}>;
};
}, {}, {}>
trpc.post: TrpcQueryUtils<ClientRouter<{
byId: BuildProcedure<InputDef<RootDef<Context, {}>, ZodObject<{
id: ZodString;
}, $strip>>, "query", {
output: Post;
errors: TrpcError<"NOT_FOUND", {
id: string;
}>;
services: never;
unmapped: never;
}>;
list: BuildProcedure<RootDef<Context, {}>, "query", {
output: Post[];
errors: never;
services: never;
unmapped: never;
}>;
create: BuildProcedure<InputDef<With<RootDef<Context, {}>, {
ctx: Context;
ctxAdded: {
...;
};
inputOut: Unset;
errors: TrpcError<...>;
shorts: never;
}>, ZodObject<...>>, "mutation", {
...;
}>;
}, {}, undefined, {}>>
post.create: MutationProcedureUtils<{
...;
}, {
id: string;
title: string;
author: string | null;
createdAt: string;
}, NonNullable<...>, Omit<...>>
create.MutationProcedureUtils<{ title: string; }, { id: string; title: string; author: string | null; createdAt: string; }, NonNullable<UnexpectedError | (TrpcError<"UNAUTHORIZED", undefined> & { ...; }) | (TrpcError<...> & { ...; })>, Omit<...>>.mutationOptions<undefined>(opts?: (ContextBag<Omit<NonNullable<{
signal?: AbortSignal | undefined;
} & BuiltinCallOptions>, "signal" | "lastEventId">> & MutationOptionsIn<{
title: string;
}, {
id: string;
title: string;
author: string | null;
createdAt: string;
}, NonNullable<UnexpectedError | (TrpcError<"UNAUTHORIZED", undefined> & {
readonly defined: true;
}) | (TrpcError<"BAD_REQUEST", InputValidationErrorData<{
readonly code: "invalid_type";
readonly expected: $ZodInvalidTypeExpected;
readonly path: readonly [] | readonly [...];
readonly message: string;
} | ... 10 more ... | {
...;
}>> & {
...;
})>, undefined>) | undefined): MutationOptionsOut<...>
mutationOptions({
onSuccess?: ((data: {
id: string;
title: string;
author: string | null;
createdAt: string;
}, variables: {
title: string;
}, onMutateResult: undefined, context: MutationFunctionContext) => Promise<unknown> | unknown) | undefined
onSuccess: () =>
this.PostComponent.queryClient: QueryClientqueryClient.QueryClient.invalidateQueries<TrpcQueryKey>(filters?: InvalidateQueryFilters<TrpcQueryKey> | undefined, options?: InvalidateOptions): Promise<void>invalidateQueries(this.PostComponent.trpc: TrpcQueryUtilsFor<{
post: {
byId: BuildProcedure<InputDef<RootDef<Context, {}>, ZodObject<{
id: ZodString;
}, $strip>>, "query", {
output: Post;
errors: TrpcError<"NOT_FOUND", {
id: string;
}>;
services: never;
unmapped: never;
}>;
list: BuildProcedure<RootDef<Context, {}>, "query", {
output: Post[];
errors: never;
services: never;
unmapped: never;
}>;
create: BuildProcedure<InputDef<With<RootDef<Context, {}>, {
ctx: Context;
ctxAdded: {
...;
};
inputOut: Unset;
errors: TrpcError<...>;
shorts: never;
}>, ZodObject<...>>, "mutation", {
...;
}>;
};
}, {}, {}>
trpc.post: TrpcQueryUtils<ClientRouter<{
byId: BuildProcedure<InputDef<RootDef<Context, {}>, ZodObject<{
id: ZodString;
}, $strip>>, "query", {
output: Post;
errors: TrpcError<"NOT_FOUND", {
id: string;
}>;
services: never;
unmapped: never;
}>;
list: BuildProcedure<RootDef<Context, {}>, "query", {
output: Post[];
errors: never;
services: never;
unmapped: never;
}>;
create: BuildProcedure<InputDef<With<RootDef<Context, {}>, {
ctx: Context;
ctxAdded: {
...;
};
inputOut: Unset;
errors: TrpcError<...>;
shorts: never;
}>, ZodObject<...>>, "mutation", {
...;
}>;
}, {}, undefined, {}>>
post.PathUtils.pathFilter(filters?: QueryFiltersIn): QueryFiltersIn & {
queryKey: TrpcQueryKey;
}
pathFilter()),
}),
);
}Subscriptions
injectSubscription subscribes from the first browser render until the injector is destroyed, and not during SSR. It returns signals, status, data (the latest event) and error, with reset(). The function is tracked, and a new input restarts the subscription. Outside an injection context, pass { injector }:
@function Component(obj: Component): TypeDecoratorComponent({ Directive.selector?: string | undefinedselector: 'app-ticker', Component.template?: string | undefinedtemplate: `<p>{{ ticks.data() }}</p>` })
export class class TickerComponentTickerComponent {
TickerComponent.trpc: TrpcQueryUtilsFor<{
clock: {
ticks: BuildProcedure<InputDef<RootDef<Context, {}>, z.ZodObject<{
from: z.ZodNumber;
}, z.core.$strip>>, "subscription", {
output: number;
errors: never;
services: never;
}>;
};
}, {}, {}>
trpc = const injectTrpc: () => TrpcQueryUtilsFor<{
clock: {
ticks: BuildProcedure<InputDef<RootDef<Context, {}>, z.ZodObject<{
from: z.ZodNumber;
}, z.core.$strip>>, "subscription", {
output: number;
errors: never;
services: never;
}>;
};
}, {}, {}>
injectTrpc();
TickerComponent.from: WritableSignal<number>from = signal<number>(initialValue: number, options?: CreateSignalOptions<number> | undefined): WritableSignal<number>signal(10);
TickerComponent.ticks: InjectSubscriptionResult<number, NonNullable<UnexpectedError | (TrpcError<"BAD_REQUEST", InputValidationErrorData<{
readonly code: "invalid_type";
readonly expected: z.core.$ZodInvalidTypeExpected;
readonly path: readonly [] | readonly ["from"];
readonly message: string;
} | {
readonly code: "too_big";
readonly origin: "number" | "int" | "bigint" | "date" | "string" | "array" | "set" | "file" | (string & {});
readonly maximum: string | number;
readonly inclusive?: boolean | undefined;
readonly exact?: boolean | undefined;
readonly path: readonly [] | readonly ["from"];
readonly message: string;
} | {
readonly code: "too_small";
... 5 more ...;
readonly message: string;
} | ... 8 more ... | {
...;
}>> & {
...;
})>>
ticks = injectSubscription<number, NonNullable<UnexpectedError | (TrpcError<"BAD_REQUEST", InputValidationErrorData<{
readonly code: "invalid_type";
readonly expected: z.core.$ZodInvalidTypeExpected;
readonly path: readonly [] | readonly ["from"];
readonly message: string;
} | {
readonly code: "too_big";
readonly origin: "number" | "int" | "bigint" | "date" | "string" | "array" | "set" | "file" | (string & {});
readonly maximum: string | number;
readonly inclusive?: boolean | undefined;
readonly exact?: boolean | undefined;
readonly path: readonly [] | readonly ["from"];
readonly message: string;
} | {
readonly code: "too_small";
... 5 more ...;
readonly message: string;
} | ... 8 more ... | {
...;
}>> & {
...;
})>>(options: () => TrpcSubscriptionOptions<...>, opts?: InjectSubscriptionOptions): InjectSubscriptionResult<...>
injectSubscription(() =>
this.TickerComponent.trpc: TrpcQueryUtilsFor<{
clock: {
ticks: BuildProcedure<InputDef<RootDef<Context, {}>, z.ZodObject<{
from: z.ZodNumber;
}, z.core.$strip>>, "subscription", {
output: number;
errors: never;
services: never;
}>;
};
}, {}, {}>
trpc.clock: TrpcQueryUtils<ClientRouter<{
ticks: BuildProcedure<InputDef<RootDef<Context, {}>, z.ZodObject<{
from: z.ZodNumber;
}, z.core.$strip>>, "subscription", {
output: number;
errors: never;
services: never;
}>;
}, {}, undefined, {}>>
clock.ticks: SubscriptionProcedureUtils<{
from: number;
}, number, NonNullable<UnexpectedError | (TrpcError<"BAD_REQUEST", InputValidationErrorData<{
readonly code: "invalid_type";
readonly expected: z.core.$ZodInvalidTypeExpected;
readonly path: readonly [] | readonly ["from"];
readonly message: string;
} | {
readonly code: "too_big";
readonly origin: "number" | "int" | "bigint" | "date" | "string" | "array" | "set" | "file" | (string & {});
readonly maximum: string | number;
readonly inclusive?: boolean | undefined;
readonly exact?: boolean | undefined;
readonly path: readonly [] | readonly ["from"];
readonly message: string;
} | {
readonly code: "too_small";
... 5 more ...;
readonly message: string;
} | ... 8 more ... | {
...;
}>> & {
...;
})>, Omit<...>>
ticks.SubscriptionProcedureUtils<{ from: number; }, number, NonNullable<UnexpectedError | (TrpcError<"BAD_REQUEST", InputValidationErrorData<{ readonly code: "invalid_type"; readonly expected: $ZodInvalidTypeExpected; readonly path: readonly [] | readonly [...]; readonly message: string; } | ... 10 more ... | { ...; }>> & { ...; })>, Omit<...>>.subscriptionOptions(opts: {
input: {
from: number;
} | unique symbol;
} & ContextBag<Omit<NonNullable<{
signal?: AbortSignal | undefined;
} & BuiltinCallOptions & {
lastEventId?: string | undefined;
}>, "signal" | "lastEventId">> & {
enabled?: boolean | undefined;
} & SubscriptionCallbacks<number, NonNullable<UnexpectedError | (TrpcError<"BAD_REQUEST", InputValidationErrorData<{
readonly code: "invalid_type";
readonly expected: z.core.$ZodInvalidTypeExpected;
readonly path: readonly [] | readonly ["from"];
readonly message: string;
} | ... 10 more ... | {
...;
}>> & {
...;
})>>): TrpcSubscriptionOptions<...>
subscriptionOptions({ input: {
from: number;
} | unique symbol
input: { from: numberfrom: this.TickerComponent.from: WritableSignal
() => number
from() } }),
);
}What subscriptions share, and the query-cache forms (liveOptions(), streamedOptions()), are in Subscriptions.