Skip to content

Commit f358e50

Browse files
authored
🤖 Merge PR DefinitelyTyped#73350 Update types to match actual library behavior in @types/screenshot-desktop by @radiantbeing
1 parent f7c726e commit f358e50

File tree

3 files changed

+58
-46
lines changed

3 files changed

+58
-46
lines changed

types/screenshot-desktop/index.d.ts

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,37 @@
33
export = screenshotDesktop;
44

55
declare function screenshotDesktop(
6-
options?: { format?: screenshotDesktop.ImageFormat; screen?: screenshotDesktop.DisplayID },
7-
): Promise<Buffer>;
6+
options?: screenshotDesktop.ScreenshotOptionsWithoutFilename,
7+
): Promise<NonSharedBuffer>;
88
declare function screenshotDesktop(
9-
options?: { filename: string; format?: screenshotDesktop.ImageFormat; screen?: screenshotDesktop.DisplayID },
9+
options?: screenshotDesktop.ScreenshotOptionsWithFilename,
1010
): Promise<string>;
1111

1212
declare namespace screenshotDesktop {
13-
type DisplayID = number;
14-
15-
type ImageFormat =
16-
| "bmp"
17-
| "emf"
18-
| "exif"
19-
| "jpg"
20-
| "jpeg"
21-
| "gif"
22-
| "png"
23-
| "tiff"
24-
| "wmf";
25-
26-
function listDisplays(): Promise<Array<{ id: DisplayID; name: string }>>;
27-
function all(): Promise<Array<{ id: DisplayID; name: string }>>;
13+
interface ScreenshotOptions {
14+
filename?: string;
15+
format?: ImageFormat;
16+
screen?: DisplayID;
17+
linuxLibrary?: "scrot" | "imagemagick";
18+
}
19+
20+
interface ScreenshotOptionsWithFilename extends ScreenshotOptions {
21+
filename: string;
22+
}
23+
24+
interface ScreenshotOptionsWithoutFilename extends ScreenshotOptions {
25+
filename?: "";
26+
}
27+
28+
interface Display {
29+
id: number | string;
30+
name: string;
31+
}
32+
33+
type DisplayID = Display["id"];
34+
35+
type ImageFormat = "jpg" | "png";
36+
37+
function listDisplays(): Promise<Array<Display>>;
38+
function all(): Promise<Array<NonSharedBuffer>>;
2839
}

types/screenshot-desktop/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"name": "@types/screenshot-desktop",
4-
"version": "1.12.9999",
4+
"version": "1.15.9999",
55
"projects": [
66
"https://github.com/bencevans/screenshot-desktop"
77
],
Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
11
import screenshot = require("screenshot-desktop");
22

3-
screenshot().then((img) => {
4-
// img: Buffer filled with jpg goodness
5-
// ...
6-
}).catch((err) => {
7-
// ...
8-
});
3+
// Buffer filled with jpg goodness
4+
// $ExpectType Promise<NonSharedBuffer> || Promise<Buffer>
5+
screenshot();
96

10-
screenshot({ format: "png" }).then((img) => {
11-
// img: Buffer filled with png goodness
12-
// ...
13-
}).catch((err) => {
14-
// ...
15-
});
7+
// Buffer filled with png goodness
8+
// $ExpectType Promise<NonSharedBuffer> || Promise<Buffer>
9+
screenshot({ format: "png" });
1610

17-
screenshot.listDisplays().then((displays) => {
18-
// displays: [{ id, name }, { id, name }]
19-
screenshot({ screen: displays[displays.length - 1].id })
20-
.then((img) => {
21-
// img: Buffer of screenshot of the last display
22-
});
23-
});
11+
// Buffer when filename is empty
12+
// $ExpectType Promise<NonSharedBuffer> || Promise<Buffer>
13+
screenshot({ filename: "" });
2414

25-
screenshot.all().then((imgs) => {
26-
// imgs: an array of Buffers, one for each screen
27-
});
15+
// absolute path to screenshot
16+
// created in current working directory named shot.jpg
17+
// $ExpectType Promise<string>
18+
screenshot({ filename: "shot.jpg" });
2819

29-
screenshot({ filename: "shot.jpg" }).then((imgPath) => {
30-
// imgPath: absolute path to screenshot
31-
// created in current working directory named shot.png
20+
// absolute paths work too. so do pngs
21+
// $ExpectType Promise<string>
22+
screenshot({ filename: "/Users/$USER/Desktop/demo.png" });
23+
24+
// an array of available displays
25+
// $ExpectType Promise<Display[]>
26+
screenshot.listDisplays();
27+
28+
screenshot.listDisplays().then((displays) => {
29+
// Buffer of screenshot of the last display
30+
// $ExpectType Promise<NonSharedBuffer> || Promise<Buffer>
31+
screenshot({ screen: displays[displays.length - 1].id });
3232
});
3333

34-
// absolute paths work too. so do pngs
35-
screenshot({ filename: "/Users/brian/Desktop/demo.png" });
34+
// an array of Buffers or strings, one for each screen
35+
// $ExpectType Promise<NonSharedBuffer[]> || Promise<Buffer[]>
36+
screenshot.all();

0 commit comments

Comments
 (0)