Skip to content

Commit ee7b6af

Browse files
committed
fix: return type by overloading and forward export ParsedCSS
1 parent 67784dc commit ee7b6af

4 files changed

Lines changed: 36 additions & 3 deletions

File tree

src/Inspector.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,15 @@ export class Inspector extends EventEmitter {
552552
});
553553
}
554554

555+
// Function overloads for getMatchedStyles
556+
async getMatchedStyles(
557+
element: InspectorElement,
558+
options: MatchedStylesOptions & { raw: true },
559+
): Promise<GetMatchedStylesForNodeResponse>;
560+
async getMatchedStyles(
561+
element: InspectorElement,
562+
options?: MatchedStylesOptions & { raw?: false },
563+
): Promise<ParsedCSS>;
555564
async getMatchedStyles(
556565
element: InspectorElement,
557566
options: MatchedStylesOptions = {},
@@ -572,6 +581,15 @@ export class Inspector extends EventEmitter {
572581
return raw ? ret : parseGetMatchedStylesForNodeResponse(ret, parseOptions);
573582
}
574583

584+
// Function overloads for getComputedStyle
585+
async getComputedStyle(
586+
element: InspectorElement,
587+
options: ComputedStyleOptions & { raw: true },
588+
): Promise<GetComputedStyleForNodeResponse>;
589+
async getComputedStyle(
590+
element: InspectorElement,
591+
options?: ComputedStyleOptions & { raw?: false },
592+
): Promise<Record<string, string>>;
575593
async getComputedStyle(
576594
element: InspectorElement,
577595
options: ComputedStyleOptions = {},

src/InspectorDOM.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,19 +326,31 @@ export class InspectorElement extends InspectorNode {
326326
/**
327327
* @experimental
328328
*/
329+
async getMatchedStyles(
330+
options: MatchedStylesOptions & { raw: true },
331+
): Promise<GetMatchedStylesForNodeResponse>;
332+
async getMatchedStyles(
333+
options?: MatchedStylesOptions & { raw?: false },
334+
): Promise<ParsedCSS>;
329335
async getMatchedStyles(
330336
options: MatchedStylesOptions = {},
331337
): Promise<GetMatchedStylesForNodeResponse | ParsedCSS> {
332-
return await this.inspector.getMatchedStyles(this, options);
338+
return await this.inspector.getMatchedStyles(this, options as any); // FIXME
333339
}
334340

335341
/**
336342
* @experimental
337343
*/
344+
async getComputedStyle(
345+
options: ComputedStyleOptions & { raw: true },
346+
): Promise<GetComputedStyleForNodeResponse>;
347+
async getComputedStyle(
348+
options?: ComputedStyleOptions & { raw?: false },
349+
): Promise<Record<string, string>>;
338350
async getComputedStyle(
339351
options: ComputedStyleOptions = {},
340352
): Promise<Record<string, string> | GetComputedStyleForNodeResponse> {
341-
return await this.inspector.getComputedStyle(this, options);
353+
return await this.inspector.getComputedStyle(this, options as any); // FIXME
342354
}
343355
}
344356

src/index.shared.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
export * from "./constants.js";
22
export * from "./types.js";
33
export * from "./InspectorDOM.js";
4+
5+
// for user to type function parameters accepting the returned value
6+
export { ParsedCSS } from "@devtoolcss/parser";

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export type GetMatchedStylesForNodeResponse = {
1818
};
1919

2020
export type GetComputedStyleForNodeResponse = {
21-
computedStyle: Record<string, string>[];
21+
computedStyle: { name: string; value: string }[];
2222
extraFields: Object;
2323
};
2424

0 commit comments

Comments
 (0)