Skip to content

Commit

Permalink
🤖 Merge PR #69493 fix(wktohtml): fix callback and return types by @ma…
Browse files Browse the repository at this point in the history
  • Loading branch information
marievidal360 committed May 2, 2024
1 parent c47f496 commit bc8f834
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
16 changes: 11 additions & 5 deletions types/wkhtmltopdf/index.d.ts
Expand Up @@ -3,6 +3,8 @@

/// <reference types="node"/>

import { Readable } from "stream";

/**
* Call wkhtmltopdf and write PDF
* If options.output is defined the file will be returned in the stream
Expand All @@ -13,8 +15,8 @@
declare function wkhtmltopdf(
html: string,
options?: Options,
callback?: (err: Error, stream: NodeJS.ReadWriteStream) => void,
): NodeJS.ReadWriteStream;
callback?: (err: Error | null, stream?: NodeJS.ReadWriteStream) => void,
): Readable;
/**
* Call wkhtmltopdf and write PDF
* If options.output is defined the file will be returned in the stream
Expand All @@ -26,8 +28,8 @@ declare function wkhtmltopdf(
declare function wkhtmltopdf(
url: string,
options?: Options,
callback?: (err: Error, stream: NodeJS.ReadWriteStream) => void,
): NodeJS.ReadWriteStream;
callback?: (err: Error | null, stream?: NodeJS.ReadWriteStream) => void,
): Readable;
/**
* Call wkhtmltopdf and write PDF
* If options.output is defined the file will be returned in the stream
Expand All @@ -36,7 +38,11 @@ declare function wkhtmltopdf(
* @param [options] Options
* @param [callback] Callback
*/
declare function wkhtmltopdf(inputStream: NodeJS.ReadStream, options?: Options): NodeJS.ReadWriteStream;
declare function wkhtmltopdf(
inputStream: NodeJS.ReadStream,
options?: Options,
callback?: (err: Error | null, stream?: NodeJS.ReadWriteStream) => void,
): Readable;

declare namespace wkhtmltopdf {
/**
Expand Down
30 changes: 20 additions & 10 deletions types/wkhtmltopdf/wkhtmltopdf-tests.ts
@@ -1,19 +1,24 @@
import wkhtmltopdf = require("wkhtmltopdf");

// URL
wkhtmltopdf("http://google.com/", { pageSize: "Letter" }); // $ExpectType NodeJS.ReadWriteStream
// $ExpectType Readable
wkhtmltopdf("http://google.com/", { pageSize: "Letter" });

// HTML
wkhtmltopdf("<h1>Test</h1><p>Hello world</p>"); // $ExpectType ReadWriteStream
// $ExpectType Readable
wkhtmltopdf("<h1>Test</h1><p>Hello world</p>");

// output to a file directly
wkhtmltopdf("http://apple.com/", { output: "out.pdf" }); // $ExpectType ReadWriteStream
// $ExpectType Readable
wkhtmltopdf("http://apple.com/", { output: "out.pdf" });

// Optional callback
wkhtmltopdf("http://google.com/", { pageSize: "Letter" }, (err: Error, stream: NodeJS.ReadWriteStream) => {}); // $ExpectType void
// $ExpectType Readable
wkhtmltopdf("http://google.com/", { pageSize: "Letter" }, (err: Error | null, stream?: NodeJS.ReadWriteStream) => {});

// Repeatable options
wkhtmltopdf("http://google.com/", { // $ExpectType NodeJS.ReadWriteStream
// $ExpectType Readable
wkhtmltopdf("http://google.com/", {
allow: ["path1", "path2"],
customHeader: [
["name1", "value1"],
Expand All @@ -22,23 +27,27 @@ wkhtmltopdf("http://google.com/", { // $ExpectType NodeJS.ReadWriteStream
});

// Ignore warning strings
wkhtmltopdf("http://apple.com/", { // $ExpectType ReadWriteStream
// $ExpectType Readable
wkhtmltopdf("http://apple.com/", {
output: "out.pdf",
ignore: ["QFont::setPixelSize: Pixel size <= 0 (0)"],
});

// RegExp also acceptable
wkhtmltopdf("http://apple.com/", { // $ExpectType ReadWriteStream
// $ExpectType Readable
wkhtmltopdf("http://apple.com/", {
output: "out.pdf",
ignore: [/QFont::setPixelSize/],
});

// Test debug types
wkhtmltopdf("http://apple.com/", { // $ExpectType ReadWriteStream
// $ExpectType Readable
wkhtmltopdf("http://apple.com/", {
debug: true,
});

wkhtmltopdf("http://apple.com/", { // $ExpectType ReadWriteStream
// $ExpectType Readable
wkhtmltopdf("http://apple.com/", {
output: "test.pdf",
debug: (data: Buffer) => {
const dataString = data.toString();
Expand All @@ -56,7 +65,8 @@ wkhtmltopdf.shell; // $ExpectType string
wkhtmltopdf.command; // $ExpectType string

// Footer and header spacing type
wkhtmltopdf("http://apple.com/", { // $ExpectType ReadWriteStream
// $ExpectType Readable
wkhtmltopdf("http://apple.com/", {
headerSpacing: 0,
footerSpacing: 0,
});

0 comments on commit bc8f834

Please sign in to comment.