Skip to content

Commit 0b0a23e

Browse files
authored
chore: Fix HttpCrawler context types (#3291)
1 parent 665c690 commit 0b0a23e

File tree

8 files changed

+36
-30
lines changed

8 files changed

+36
-30
lines changed

packages/basic-crawler/src/internals/basic-crawler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export type RequireContextPipeline<
119119

120120
export interface BasicCrawlerOptions<
121121
Context extends CrawlingContext = CrawlingContext,
122-
ContextExtension = {},
122+
ContextExtension = Dictionary<never>,
123123
ExtendedContext extends Context = Context & ContextExtension,
124124
> {
125125
/**
@@ -471,7 +471,7 @@ export interface CrawlerExperiments {
471471
*/
472472
export class BasicCrawler<
473473
Context extends CrawlingContext = CrawlingContext,
474-
ContextExtension = {},
474+
ContextExtension = Dictionary<never>,
475475
ExtendedContext extends Context = Context & ContextExtension,
476476
> {
477477
protected static readonly CRAWLEE_STATE_KEY = 'CRAWLEE_STATE';

packages/browser-crawler/src/internals/browser-crawler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export interface BrowserCrawlerOptions<
102102
ProvidedController,
103103
Dictionary
104104
>,
105-
ContextExtension = {},
105+
ContextExtension = Dictionary<never>,
106106
ExtendedContext extends Context = Context & ContextExtension,
107107
InternalBrowserPoolOptions extends BrowserPoolOptions = BrowserPoolOptions,
108108
__BrowserPlugins extends BrowserPlugin[] = InferBrowserPluginArray<InternalBrowserPoolOptions['browserPlugins']>,
@@ -297,7 +297,7 @@ export abstract class BrowserCrawler<
297297
ProvidedController,
298298
Dictionary
299299
>,
300-
ContextExtension = {},
300+
ContextExtension = Dictionary<never>,
301301
ExtendedContext extends Context = Context & ContextExtension,
302302
GoToOptions extends Dictionary = Dictionary,
303303
> extends BasicCrawler<Context, ContextExtension, ExtendedContext> {

packages/cheerio-crawler/src/internals/cheerio-crawler.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ export type CheerioErrorHandler<
2525
> = ErrorHandler<CheerioCrawlingContext<UserData, JSONData>>;
2626

2727
export interface CheerioCrawlerOptions<
28-
ExtendedContext extends CheerioCrawlingContext,
28+
ContextExtension = Dictionary<never>,
29+
ExtendedContext extends CheerioCrawlingContext = CheerioCrawlingContext & ContextExtension,
2930
UserData extends Dictionary = any, // with default to Dictionary we cant use a typed router in untyped crawler
3031
JSONData extends Dictionary = any, // with default to Dictionary we cant use a typed router in untyped crawler
31-
> extends HttpCrawlerOptions<CheerioCrawlingContext<UserData, JSONData>, ExtendedContext> {}
32+
> extends HttpCrawlerOptions<CheerioCrawlingContext<UserData, JSONData>, ContextExtension, ExtendedContext> {}
3233

3334
export type CheerioHook<
3435
UserData extends Dictionary = any, // with default to Dictionary we cant use a typed router in untyped crawler
@@ -169,12 +170,13 @@ export type CheerioRequestHandler<
169170
* @category Crawlers
170171
*/
171172
export class CheerioCrawler<
172-
ExtendedContext extends CheerioCrawlingContext = CheerioCrawlingContext,
173-
> extends HttpCrawler<CheerioCrawlingContext, ExtendedContext> {
173+
ContextExtension = Dictionary<never>,
174+
ExtendedContext extends CheerioCrawlingContext = CheerioCrawlingContext & ContextExtension,
175+
> extends HttpCrawler<CheerioCrawlingContext, ContextExtension, ExtendedContext> {
174176
/**
175177
* All `CheerioCrawler` parameters are passed via an options object.
176178
*/
177-
constructor(options?: CheerioCrawlerOptions<ExtendedContext>, config?: Configuration) {
179+
constructor(options?: CheerioCrawlerOptions<ContextExtension, ExtendedContext>, config?: Configuration) {
178180
super(
179181
{
180182
...options,

packages/http-crawler/src/internals/http-crawler.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ export type HttpErrorHandler<
7575

7676
export interface HttpCrawlerOptions<
7777
Context extends InternalHttpCrawlingContext = InternalHttpCrawlingContext,
78-
ExtendedContext extends Context = Context,
79-
> extends BasicCrawlerOptions<Context, ExtendedContext> {
78+
ContextExtension = Dictionary<never>,
79+
ExtendedContext extends Context = Context & ContextExtension,
80+
> extends BasicCrawlerOptions<Context, ContextExtension, ExtendedContext> {
8081
/**
8182
* Timeout in which the HTTP request to the resource needs to finish, given in seconds.
8283
*/
@@ -325,9 +326,9 @@ export type HttpRequestHandler<
325326
*/
326327
export class HttpCrawler<
327328
Context extends InternalHttpCrawlingContext<any, any> = InternalHttpCrawlingContext,
328-
ContextExtension = {},
329+
ContextExtension = Dictionary<never>,
329330
ExtendedContext extends Context = Context & ContextExtension,
330-
> extends BasicCrawler<Context, ExtendedContext> {
331+
> extends BasicCrawler<Context, ContextExtension, ExtendedContext> {
331332
protected preNavigationHooks: InternalHttpHook<CrawlingContext>[];
332333
protected postNavigationHooks: ((crawlingContext: CrawlingContextWithReponse) => Awaitable<void>)[];
333334
protected persistCookiesPerSession: boolean;
@@ -360,7 +361,7 @@ export class HttpCrawler<
360361
* All `HttpCrawlerOptions` parameters are passed via an options object.
361362
*/
362363
constructor(
363-
options: HttpCrawlerOptions<Context, ExtendedContext> &
364+
options: HttpCrawlerOptions<Context, ContextExtension, ExtendedContext> &
364365
RequireContextPipeline<InternalHttpCrawlingContext, Context> = {} as any,
365366
override readonly config = Configuration.getGlobalConfig(),
366367
) {

packages/jsdom-crawler/src/internals/jsdom-crawler.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ export type JSDOMErrorHandler<
3434
> = ErrorHandler<JSDOMCrawlingContext<UserData, JSONData>>;
3535

3636
export interface JSDOMCrawlerOptions<
37-
ExtendedContext extends JSDOMCrawlingContext = JSDOMCrawlingContext,
37+
ContextExtension = Dictionary<never>,
38+
ExtendedContext extends JSDOMCrawlingContext = JSDOMCrawlingContext & ContextExtension,
3839
UserData extends Dictionary = any, // with default to Dictionary we cant use a typed router in untyped crawler
3940
JSONData extends Dictionary = any, // with default to Dictionary we cant use a typed router in untyped crawler
40-
> extends HttpCrawlerOptions<JSDOMCrawlingContext<UserData, JSONData>, ExtendedContext> {
41+
> extends HttpCrawlerOptions<JSDOMCrawlingContext<UserData, JSONData>, ContextExtension, ExtendedContext> {
4142
/**
4243
* Download and run scripts.
4344
*/
@@ -177,10 +178,10 @@ const resources = new ResourceLoader({
177178
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36',
178179
});
179180

180-
export class JSDOMCrawler<ExtendedContext extends JSDOMCrawlingContext = JSDOMCrawlingContext> extends HttpCrawler<
181-
JSDOMCrawlingContext,
182-
ExtendedContext
183-
> {
181+
export class JSDOMCrawler<
182+
ContextExtension = Dictionary<never>,
183+
ExtendedContext extends JSDOMCrawlingContext = JSDOMCrawlingContext & ContextExtension,
184+
> extends HttpCrawler<JSDOMCrawlingContext, ContextExtension, ExtendedContext> {
184185
protected static override optionsShape = {
185186
...HttpCrawler.optionsShape,
186187
runScripts: ow.optional.boolean,
@@ -191,7 +192,7 @@ export class JSDOMCrawler<ExtendedContext extends JSDOMCrawlingContext = JSDOMCr
191192
protected hideInternalConsole: boolean;
192193
protected virtualConsole: VirtualConsole | null = null;
193194

194-
constructor(options: JSDOMCrawlerOptions<ExtendedContext> = {}, config?: Configuration) {
195+
constructor(options: JSDOMCrawlerOptions<ContextExtension, ExtendedContext> = {}, config?: Configuration) {
195196
const { runScripts = false, hideInternalConsole = false, ...httpOptions } = options;
196197

197198
super(

packages/linkedom-crawler/src/internals/linkedom-crawler.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ export type LinkeDOMErrorHandler<
2929
> = ErrorHandler<LinkeDOMCrawlingContext<UserData, JSONData>>;
3030

3131
export interface LinkeDOMCrawlerOptions<
32-
ExtendedContext extends LinkeDOMCrawlingContext,
32+
ContextExtension = Dictionary<never>,
33+
ExtendedContext extends LinkeDOMCrawlingContext = LinkeDOMCrawlingContext & ContextExtension,
3334
UserData extends Dictionary = any, // with default to Dictionary we cant use a typed router in untyped crawler
3435
JSONData extends Dictionary = any, // with default to Dictionary we cant use a typed router in untyped crawler
35-
> extends HttpCrawlerOptions<LinkeDOMCrawlingContext<UserData, JSONData>, ExtendedContext> {}
36+
> extends HttpCrawlerOptions<LinkeDOMCrawlingContext<UserData, JSONData>, ContextExtension, ExtendedContext> {}
3637

3738
export interface LinkeDOMCrawlerEnqueueLinksOptions extends Omit<EnqueueLinksOptions, 'urls' | 'requestQueue'> {}
3839

@@ -160,11 +161,12 @@ export type LinkeDOMRequestHandler<
160161
*/
161162

162163
export class LinkeDOMCrawler<
163-
ExtendedContext extends LinkeDOMCrawlingContext = LinkeDOMCrawlingContext,
164-
> extends HttpCrawler<LinkeDOMCrawlingContext, ExtendedContext> {
164+
ContextExtension = Dictionary<never>,
165+
ExtendedContext extends LinkeDOMCrawlingContext = LinkeDOMCrawlingContext & ContextExtension,
166+
> extends HttpCrawler<LinkeDOMCrawlingContext, ContextExtension, ExtendedContext> {
165167
private static parser = new DOMParser();
166168

167-
constructor(options: LinkeDOMCrawlerOptions<ExtendedContext>) {
169+
constructor(options: LinkeDOMCrawlerOptions<ContextExtension, ExtendedContext>) {
168170
super({
169171
...options,
170172
contextPipelineBuilder: () =>

packages/playwright-crawler/src/internals/playwright-crawler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export interface PlaywrightHook extends BrowserHook<PlaywrightCrawlingContext, P
3333
export type PlaywrightGotoOptions = Parameters<Page['goto']>[1];
3434

3535
export interface PlaywrightCrawlerOptions<
36-
ContextExtension = {},
36+
ContextExtension = Dictionary<never>,
3737
ExtendedContext extends PlaywrightCrawlingContext = PlaywrightCrawlingContext & ContextExtension,
3838
> extends BrowserCrawlerOptions<
3939
Page,
@@ -176,7 +176,7 @@ export interface PlaywrightCrawlerOptions<
176176
* @category Crawlers
177177
*/
178178
export class PlaywrightCrawler<
179-
ContextExtension = {},
179+
ContextExtension = Dictionary<never>,
180180
ExtendedContext extends PlaywrightCrawlingContext = PlaywrightCrawlingContext & ContextExtension,
181181
> extends BrowserCrawler<
182182
Page,

packages/puppeteer-crawler/src/internals/puppeteer-crawler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export interface PuppeteerHook extends BrowserHook<PuppeteerCrawlingContext, Pup
3232
export type PuppeteerGoToOptions = Parameters<Page['goto']>[1];
3333

3434
export interface PuppeteerCrawlerOptions<
35-
ContextExtension = {},
35+
ContextExtension = Dictionary<never>,
3636
ExtendedContext extends PuppeteerCrawlingContext = PuppeteerCrawlingContext & ContextExtension,
3737
> extends BrowserCrawlerOptions<
3838
Page,
@@ -149,7 +149,7 @@ export interface PuppeteerCrawlerOptions<
149149
* @category Crawlers
150150
*/
151151
export class PuppeteerCrawler<
152-
ContextExtension = {},
152+
ContextExtension = Dictionary<never>,
153153
ExtendedContext extends PuppeteerCrawlingContext = PuppeteerCrawlingContext & ContextExtension,
154154
> extends BrowserCrawler<
155155
Page,

0 commit comments

Comments
 (0)