Skip to content

Commit

Permalink
fix: import Observable as a type (#826)
Browse files Browse the repository at this point in the history
* import Observable as a type

* fix: only generation of services should import Observable as a type, the test suite should stay as it is
  • Loading branch information
spheenik authored May 7, 2023
1 parent e60706b commit 52e84ba
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/generate-services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ export function generateRpcType(ctx: Context, hasStreamingMethods: boolean): Cod
const maybeAbortSignalParam = options.useAbortSignal ? "abortSignal?: AbortSignal," : "";
const methods = [[code`request`, code`Uint8Array`, code`Promise<Uint8Array>`]];
if (hasStreamingMethods) {
const observable = observableType(ctx);
const observable = observableType(ctx, true);
methods.push([code`clientStreamingRequest`, code`${observable}<Uint8Array>`, code`Promise<Uint8Array>`]);
methods.push([code`serverStreamingRequest`, code`Uint8Array`, code`${observable}<Uint8Array>`]);
methods.push([
Expand Down
7 changes: 5 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -690,11 +690,14 @@ export function rawRequestType(
return messageToTypeName(ctx, methodDesc.inputType, typeOptions);
}

export function observableType(ctx: Context): Code {
export function observableType(ctx: Context, asType: boolean = false): Code {
if (ctx.options.useAsyncIterable) {
return code`AsyncIterable`;
} else if (asType) {
return code`${imp("t:Observable@rxjs")}`;
} else {
return code`${imp("Observable@rxjs")}`;
}
return code`${imp("Observable@rxjs")}`;
}

export function requestType(ctx: Context, methodDesc: MethodDescriptorProto, partial: boolean = false): Code {
Expand Down

0 comments on commit 52e84ba

Please sign in to comment.