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: fix type definition for undici #106

Merged
merged 1 commit into from
May 7, 2022
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
4 changes: 2 additions & 2 deletions src/undici/cookie_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ const kCookieOptions = Symbol('cookieOptions');
const kAppendCookieHeader = Symbol('appendCookieHeader');

function createCookieClient<BaseClient extends Client = Client, BaseClientOptions = Client.Options>(
BaseAgentClass: new (origin: string | URL, options: BaseClientOptions) => BaseClient,
BaseClientClass: new (origin: string | URL, options: BaseClientOptions) => BaseClient,
) {
type CookieClientOptions = BaseClientOptions & {
cookies?: CookieOptions | undefined;
};

// @ts-expect-error ...
class CookieClient extends BaseAgentClass {
class CookieClient extends BaseClientClass {
private [kCookieOptions]: CookieOptions | undefined;

constructor(
Expand Down
21 changes: 10 additions & 11 deletions undici/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
import type { CookieJar } from 'tough-cookie';
import type { Agent, Client } from 'undici';

interface CookieOptions {
export interface CookieOptions {
async_UNSTABLE?: true;
jar: CookieJar;
}

namespace CookieAgent {
export namespace CookieAgent {
export interface Options extends Agent.Options {
cookies?: CookieOptions | undefined;
}
}

class CookieAgent extends Agent {
constructor(options: CookieAgent.Options = {});
export class CookieAgent extends Agent {
constructor(options?: CookieAgent.Options);
}

namespace CookieClient {
export namespace CookieClient {
export interface Options extends Client.Options {
cookies?: CookieOptions | undefined;
}
}

class CookieClient extends Client {
export class CookieClient extends Client {
constructor(url: string | URL, options?: CookieClient.Options);
}

function createCookieClient<BaseClient extends Client = Client, BaseClientOptions = unknown>(
BaseClient: new (origin: URL, options: BaseClientOptions) => BaseClient,
): new (origin: URL, options: BaseClientOptions & { cookies?: CookieOptions | undefined }) => CookieAgent<BaseAgent>;

export { CookieAgent, CookieClient, createCookieClient };
export function createCookieClient<BaseClient extends Client = Client, BaseClientOptions = unknown>(
BaseClientClass: new (origin: string | URL, options: BaseClientOptions) => BaseClient,
): new (origin: string | URL, options?: BaseClientOptions & { cookies?: CookieOptions | undefined }) => BaseClient;