Skip to content

Commit 9ec7983

Browse files
authored
🤖 Merge PR DefinitelyTyped#73719 [chrome] update printerProvider namespace by @erwanjugand
1 parent b09e28b commit 9ec7983

File tree

2 files changed

+106
-27
lines changed

2 files changed

+106
-27
lines changed

‎types/chrome/index.d.ts‎

Lines changed: 63 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7899,58 +7899,94 @@ declare namespace chrome {
78997899
id: string;
79007900
/** Printer's human readable name. */
79017901
name: string;
7902-
/** Optional. Printer's human readable description. */
7902+
/** Printer's human readable description. */
79037903
description?: string | undefined;
79047904
}
79057905

7906+
/** Error codes returned in response to {@link onPrintRequested} event. */
7907+
export enum PrintError {
7908+
/** Specifies that the operation was completed successfully. */
7909+
OK = "OK",
7910+
/** Specifies that a general failure occured. */
7911+
FAILED = "FAILED",
7912+
/** Specifies that the print ticket is invalid. For example, the ticket is inconsistent with some capabilities, or the extension is not able to handle all settings from the ticket. */
7913+
INVALID_TICKET = "INVALID_TICKET",
7914+
/** Specifies that the document is invalid. For example, data may be corrupted or the format is incompatible with the extension. */
7915+
INVALID_DATA = "INVALID_DATA",
7916+
}
7917+
79067918
export interface PrinterCapabilities {
79077919
/** Device capabilities in CDD format. */
7908-
capabilities: any;
7920+
capabilities: { [key: string]: unknown };
79097921
}
79107922

79117923
export interface PrintJob {
79127924
/** ID of the printer which should handle the job. */
79137925
printerId: string;
79147926
/** The print job title. */
79157927
title: string;
7916-
/** Print ticket in CJT format. */
7928+
/** Print ticket in CJT format. */
79177929
ticket: { [key: string]: unknown };
7918-
/** The document content type. Supported formats are "application/pdf" and "image/pwg-raster". */
7930+
/** The document content type. Supported formats are `application/pdf` and `image/pwg-raster`. */
79197931
contentType: string;
7920-
/** Blob containing the document data to print. Format must match |contentType|. */
7932+
/** Blob containing the document data to print. Format must match `contentType`. */
79217933
document: Blob;
79227934
}
79237935

7924-
export interface PrinterRequestedEvent
7925-
extends chrome.events.Event<(resultCallback: (printerInfo: PrinterInfo[]) => void) => void>
7926-
{}
7927-
7928-
export interface PrinterInfoRequestedEvent
7929-
extends chrome.events.Event<(device: any, resultCallback: (printerInfo?: PrinterInfo) => void) => void>
7930-
{}
7931-
7932-
export interface CapabilityRequestedEvent extends
7933-
chrome.events.Event<
7934-
(printerId: string, resultCallback: (capabilities: PrinterCapabilities) => void) => void
7935-
>
7936-
{}
7937-
7938-
export interface PrintRequestedEvent
7939-
extends chrome.events.Event<(printJob: PrintJob, resultCallback: (result: string) => void) => void>
7940-
{}
7936+
/** from https://developer.chrome.com/docs/apps/reference/usb#type-Device */
7937+
export interface Device {
7938+
/** An opaque ID for the USB device. It remains unchanged until the device is unplugged. */
7939+
device: number;
7940+
/**
7941+
* The iManufacturer string read from the device, if available.
7942+
* @since Chrome 46
7943+
*/
7944+
manufacturerName: string;
7945+
/** The product ID. */
7946+
productId: number;
7947+
/**
7948+
* The iProduct string read from the device, if available.
7949+
* @since Chrome 46
7950+
*/
7951+
productName: string;
7952+
/**
7953+
* The iSerialNumber string read from the device, if available.
7954+
* @since Chrome 46
7955+
*/
7956+
serialNumber: string;
7957+
/** The device vendor ID. */
7958+
vendorId: number;
7959+
/**
7960+
* The device version (bcdDevice field).
7961+
* @since Chrome 51
7962+
*/
7963+
version: number;
7964+
}
79417965

79427966
/** Event fired when print manager requests printers provided by extensions. */
7943-
export var onGetPrintersRequested: PrinterRequestedEvent;
7967+
export const onGetPrintersRequested: events.Event<
7968+
(resultCallback: (printerInfo: PrinterInfo[]) => void) => void
7969+
>;
7970+
79447971
/**
79457972
* Event fired when print manager requests information about a USB device that may be a printer.
7946-
* Note: An application should not rely on this event being fired more than once per device. If a connected device is supported it should be returned in the onGetPrintersRequested event.
7973+
*
7974+
* Note: An application should not rely on this event being fired more than once per device. If a connected device is supported it should be returned in the {@link onGetPrintersRequested} event.
79477975
* @since Chrome 45
79487976
*/
7949-
export var onGetUsbPrinterInfoRequested: PrinterInfoRequestedEvent;
7977+
export const onGetUsbPrinterInfoRequested: events.Event<
7978+
(device: Device, resultCallback: (printerInfo?: PrinterInfo) => void) => void
7979+
>;
7980+
79507981
/** Event fired when print manager requests printer capabilities. */
7951-
export var onGetCapabilityRequested: CapabilityRequestedEvent;
7982+
export const onGetCapabilityRequested: events.Event<
7983+
(printerId: string, resultCallback: (capabilities: PrinterCapabilities) => void) => void
7984+
>;
7985+
79527986
/** Event fired when print manager requests printing. */
7953-
export var onPrintRequested: PrintRequestedEvent;
7987+
export const onPrintRequested: events.Event<
7988+
(printJob: PrintJob, resultCallback: (result: `${PrintError}`) => void) => void
7989+
>;
79547990
}
79557991

79567992
////////////////////

‎types/chrome/test/index.ts‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6301,6 +6301,49 @@ function testPower() {
63016301
chrome.power.reportActivity(() => {}).then(() => {});
63026302
}
63036303

6304+
// https://developer.chrome.com/docs/extensions/reference/api/printerProvider
6305+
function testPrinterProvider() {
6306+
chrome.printerProvider.PrintError.FAILED === "FAILED";
6307+
chrome.printerProvider.PrintError.INVALID_DATA === "INVALID_DATA";
6308+
chrome.printerProvider.PrintError.INVALID_TICKET === "INVALID_TICKET";
6309+
chrome.printerProvider.PrintError.OK === "OK";
6310+
6311+
const printInfo: chrome.printerProvider.PrinterInfo = {
6312+
description: "description",
6313+
id: "id",
6314+
name: "name",
6315+
};
6316+
6317+
checkChromeEvent(chrome.printerProvider.onGetCapabilityRequested, (printerId, resultCallback) => {
6318+
printerId; // $ExpectType string
6319+
resultCallback({ capabilities: {} }); // $ExpectType void
6320+
});
6321+
6322+
checkChromeEvent(chrome.printerProvider.onGetPrintersRequested, (resultCallback) => {
6323+
resultCallback([printInfo]); // $ExpectType void
6324+
});
6325+
6326+
checkChromeEvent(chrome.printerProvider.onGetUsbPrinterInfoRequested, (device, resultCallback) => {
6327+
device.device; // $ExpectType number
6328+
device.manufacturerName; // $ExpectType string
6329+
device.productId; // $ExpectType number
6330+
device.productName; // $ExpectType string
6331+
device.serialNumber; // $ExpectType string
6332+
device.vendorId; // $ExpectType number
6333+
device.version; // $ExpectType number
6334+
resultCallback(printInfo); // $ExpectType void
6335+
});
6336+
6337+
checkChromeEvent(chrome.printerProvider.onPrintRequested, (printJob, resultCallback) => {
6338+
printJob.contentType; // $ExpectType string
6339+
printJob.document; // $ExpectType Blob
6340+
printJob.printerId; // $ExpectType string
6341+
printJob.ticket; // $ExpectType { [key: string]: unknown; }
6342+
printJob.title; // $ExpectType string
6343+
resultCallback("OK"); // $ExpectType void
6344+
});
6345+
}
6346+
63046347
// https://developer.chrome.com/docs/extensions/reference/api/platformKeys
63056348
function testPlatformKeys() {
63066349
chrome.platformKeys.ClientCertificateType.ECDSA_SIGN === "ecdsaSign";

0 commit comments

Comments
 (0)