Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: SeamHttpRequest implements Promise<T> rather than PromiseLike<T> #70

Merged
merged 4 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/lib/seam/connect/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export * from './routes/index.js'
export * from './seam-http.js'
export * from './seam-http-error.js'
export * from './seam-http-multi-workspace.js'
export * from './seam-http-request.js'
razor-x marked this conversation as resolved.
Show resolved Hide resolved
export {
isApiKey,
isClientSessionToken,
Expand Down
32 changes: 28 additions & 4 deletions src/lib/seam/connect/seam-http-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ export class SeamHttpRequest<
const TResponse,
const TResponseKey extends keyof TResponse | undefined,
> implements
PromiseLike<
Promise<
TResponseKey extends keyof TResponse ? TResponse[TResponseKey] : undefined
>
{
readonly [Symbol.toStringTag]: string = 'SeamHttpRequest'

readonly #parent: SeamHttpRequestParent
readonly #config: SeamHttpRequestConfig<TResponseKey>

Expand Down Expand Up @@ -105,7 +107,7 @@ export class SeamHttpRequest<
return data
}

then<
async then<
TResult1 = TResponseKey extends keyof TResponse
? TResponse[TResponseKey]
: undefined,
Expand All @@ -123,8 +125,30 @@ export class SeamHttpRequest<
| ((reason: any) => TResult2 | PromiseLike<TResult2>)
| null
| undefined,
): PromiseLike<TResult1 | TResult2> {
return this.execute().then(onfulfilled, onrejected)
): Promise<TResult1 | TResult2> {
return await this.execute().then(onfulfilled, onrejected)
}

async catch<TResult = never>(
onrejected?:
| ((reason: any) => TResult | PromiseLike<TResult>)
| null
| undefined,
): Promise<
| (TResponseKey extends keyof TResponse
? TResponse[TResponseKey]
: undefined)
| TResult
> {
return await this.execute().catch(onrejected)
}

async finally(
onfinally?: (() => void) | null | undefined,
): Promise<
TResponseKey extends keyof TResponse ? TResponse[TResponseKey] : undefined
> {
return await this.execute().finally(onfinally)
}
}

Expand Down
Loading