Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions types/chrome/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,20 @@ type SetPartial<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
////////////////////
interface Window {
chrome: typeof chrome;

/**
* Cross-browser alias of {@link chrome}.
* @since Chrome 148 (Chrome 152 for extensions declaring a `devtools_page` in manifest)
*/
browser: typeof chrome;
}

/**
* Cross-browser alias of {@link chrome}.
* @since Chrome 148 (Chrome 152 for extensions declaring a `devtools_page` in manifest)
*/
declare var browser: typeof chrome;

declare namespace chrome {
////////////////////
// Accessibility Features
Expand Down Expand Up @@ -525,7 +537,7 @@ declare namespace chrome {
/** Device name */
deviceName: string;
/** Type of the device */
deviceType: DeviceType;
deviceType: `${DeviceType}`;
/** The user-friendly name (e.g. "USB Microphone"). */
displayName: string;
/** The unique identifier of the audio device. */
Expand All @@ -537,14 +549,14 @@ declare namespace chrome {
/** The stable/persisted device id string when available. */
stableDeviceId?: string;
/** Stream type associated with this device. */
streamType: StreamType;
streamType: `${StreamType}`;
}

interface DeviceFilter {
/** If set, only audio devices whose active state matches this value will satisfy the filter. */
isActive?: boolean;
/** If set, only audio devices whose stream type is included in this list will satisfy the filter. */
streamTypes?: StreamType[];
streamTypes?: `${StreamType}`[];
}

interface DeviceIdLists {
Expand Down Expand Up @@ -600,7 +612,7 @@ declare namespace chrome {
/** Whether or not the stream is now muted. */
isMuted: boolean;
/** The type of the stream for which the mute value changed. The updated mute value applies to all devices with this stream type. */
streamType: StreamType;
streamType: `${StreamType}`;
}

/** Type of stream an audio device provides. */
Expand All @@ -611,35 +623,41 @@ declare namespace chrome {

/**
* Gets a list of audio devices filtered based on filter.
* @param filter Device properties by which to filter the list of returned audio devices. If the filter is not set or set to `{}`, returned device list will contain all available audio devices.
*
* Can return its result via Promise in Manifest V3 or later since Chrome 116.
*/
function getDevices(filter?: DeviceFilter): Promise<AudioDeviceInfo[]>;
function getDevices(filter: DeviceFilter, callback: (devices: AudioDeviceInfo[]) => void): void;
function getDevices(callback: (devices: AudioDeviceInfo[]) => void): void;
function getDevices(filter: DeviceFilter | undefined, callback: (devices: AudioDeviceInfo[]) => void): void;

/**
* Gets the system-wide mute state for the specified stream type.
*
* Can return its result via Promise in Manifest V3 or later since Chrome 116.
*/
function getMute(streamType: `${StreamType}`): Promise<boolean>;
function getMute(streamType: `${StreamType}`, callback: (value: boolean) => void): void;

/**
* Sets lists of active input and/or output devices.
*
* Can return its result via Promise in Manifest V3 or later since Chrome 116.
*/
function setActiveDevices(ids: DeviceIdLists): Promise<void>;
function setActiveDevices(ids: DeviceIdLists, callback: () => void): void;

/**
* Sets mute state for a stream type. The mute state will apply to all audio devices with the specified audio stream type.
*
* Can return its result via Promise in Manifest V3 or later since Chrome 116.
*/
function setMute(streamType: `${StreamType}`, isMuted: boolean): Promise<void>;
function setMute(streamType: `${StreamType}`, isMuted: boolean, callback: () => void): void;

/**
* Sets the properties for the input or output device.
*
* Can return its result via Promise in Manifest V3 or later since Chrome 116.
*/
function setProperties(id: string, properties: DeviceProperties): Promise<void>;
Expand All @@ -648,18 +666,18 @@ declare namespace chrome {
/**
* Fired when audio devices change, either new devices being added, or existing devices being removed.
*/
const onDeviceListChanged: chrome.events.Event<(devices: AudioDeviceInfo[]) => void>;
const onDeviceListChanged: events.Event<(devices: AudioDeviceInfo[]) => void>;

/**
* Fired when sound level changes for an active audio device.
*/
const onLevelChanged: chrome.events.Event<(event: LevelChangedEvent) => void>;
const onLevelChanged: events.Event<(event: LevelChangedEvent) => void>;

/**
* Fired when the mute state of the audio input or output changes.
* Note that mute state is system-wide and the new value applies to every audio device with specified stream type.
*/
const onMuteChanged: chrome.events.Event<(event: MuteChangedEvent) => void>;
const onMuteChanged: events.Event<(event: MuteChangedEvent) => void>;
}

////////////////////
Expand Down
2 changes: 1 addition & 1 deletion types/chrome/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@types/chrome",
"version": "0.2.9999",
"version": "0.3.9999",
"nonNpm": "conflict",
"nonNpmDescription": "The complete reference to all APIs made available to Chrome Extensions",
"projects": [
Expand Down
38 changes: 31 additions & 7 deletions types/chrome/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2849,30 +2849,45 @@ function testAudio() {
chrome.audio.StreamType.INPUT === "INPUT";
chrome.audio.StreamType.OUTPUT === "OUTPUT";

const filter: chrome.audio.DeviceFilter = {
isActive: true,
streamTypes: ["INPUT", "OUTPUT"],
};

chrome.audio.getDevices(); // $ExpectType Promise<AudioDeviceInfo[]>
chrome.audio.getDevices({}); // $ExpectType Promise<AudioDeviceInfo[]>
chrome.audio.getDevices(devices => {}); // $ExpectType void
chrome.audio.getDevices({}, devices => {}); // $ExpectType void
chrome.audio.getDevices(undefined); // $ExpectType Promise<AudioDeviceInfo[]>
chrome.audio.getDevices(filter); // $ExpectType Promise<AudioDeviceInfo[]>
chrome.audio.getDevices(devices => { // $ExpectType void
devices; // $ExpectType AudioDeviceInfo[]
});
chrome.audio.getDevices(undefined, devices => { // $ExpectType void
devices; // $ExpectType AudioDeviceInfo[]
});
chrome.audio.getDevices(filter, devices => { // $ExpectType void
devices; // $ExpectType AudioDeviceInfo[]
});
// @ts-expect-error
chrome.audio.getDevices(() => {}).then(devices => {});

chrome.audio.getMute("INPUT"); // $ExpectType Promise<boolean>
chrome.audio.getMute("INPUT", value => {}); // $ExpectType void
chrome.audio.getMute("INPUT", value => { // $ExpectType void
value; // $ExpectType boolean
});
// @ts-expect-error
chrome.audio.getMute("INPUT", value => {}).then(value => {});

chrome.audio.setActiveDevices({}); // $ExpectType Promise<void>
chrome.audio.setActiveDevices({}, () => {}); // $ExpectType void
chrome.audio.setActiveDevices({}, () => void 0); // $ExpectType void
// @ts-expect-error
chrome.audio.setActiveDevices(() => {}).then(() => {});

chrome.audio.setMute("INPUT", true); // $ExpectType Promise<void>
chrome.audio.setMute("INPUT", true, () => {}); // $ExpectType void
chrome.audio.setMute("INPUT", true, () => void 0); // $ExpectType void
// @ts-expect-error
chrome.audio.setMute("INPUT", true, () => {}).then(() => {});

chrome.audio.setProperties("INPUT", {}); // $ExpectType Promise<void>
chrome.audio.setProperties("INPUT", {}, () => {}); // $ExpectType void
chrome.audio.setProperties("INPUT", {}, () => void 0); // $ExpectType void
// @ts-expect-error
chrome.audio.setProperties("INPUT", {}, () => {}).then(() => {});

Expand Down Expand Up @@ -8478,3 +8493,12 @@ function testWallpaper() {
// @ts-expect-error
chrome.wallpaper.setWallpaper(details, () => {}).then(() => {});
}

async function testBrowser() {
const _b: typeof browser = chrome;
const _c: typeof chrome = browser;

browser.tabs.create({ url: "https://example.test" }); // $ExpectType Promise<void>
window.browser.tabs.create({ url: "https://example.test" }); // $ExpectType Promise<void>
globalThis.browser.tabs.create({ url: "https://example.test" }); // $ExpectType Promise<void>
}
2 changes: 1 addition & 1 deletion types/google.maps/google.maps-tests.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// No tests required for generated types
// Synced from: https://github.com/googlemaps/js-types/commit/8ee4ab4f60c853ce1f5d6201e810d16713a3f272
// Synced from: https://github.com/googlemaps/js-types/commit/9a25dc1828a7b5b07410242445a8bd8332f48a99
google.maps.Map;
4 changes: 4 additions & 0 deletions types/google.maps/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10864,6 +10864,7 @@ declare namespace google.maps.marker {
content?: Node | null;
/**
* Adds the given listener function to the given event name in the Maps Eventing system.
* @deprecated Use the standard DOM <code>addEventListener()</code> method instead.
*/
addListener(eventName: string, handler: Function): google.maps.MapsEventListener;
addEventListener<K extends keyof AdvancedMarkerElementEventMap>(type: K, listener: (this: AdvancedMarkerElement, ev: AdvancedMarkerElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
Expand All @@ -10873,6 +10874,9 @@ declare namespace google.maps.marker {
}
export interface AdvancedMarkerElementEventMap extends HTMLElementEventMap {
"gmp-click": google.maps.marker.AdvancedMarkerClickEvent;
"gmp-drag": Event;
"gmp-dragend": Event;
"gmp-dragstart": Event;
}
/**
* Options for constructing an {@link google.maps.marker.AdvancedMarkerElement}.
Expand Down
2 changes: 1 addition & 1 deletion types/node/child_process.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ declare module "node:child_process" {
stderr: string | NonSharedBuffer;
}>;
}
interface ForkOptions extends ProcessEnvOptions, MessagingOptions, Abortable {
interface ForkOptions extends CommonOptions, MessagingOptions, Abortable {
execPath?: string | undefined;
execArgv?: string[] | undefined;
silent?: boolean | undefined;
Expand Down
28 changes: 20 additions & 8 deletions types/node/crypto.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ declare module "node:crypto" {
* behavior. For XOF hash functions such as `'shake256'`, the `outputLength` option
* can be used to specify the desired output length in bytes.
*
* When the data is small (< 5MB) and readily available, `crypto.hash()` is usually faster.
*
* The `algorithm` is dependent on the available algorithms supported by the
* version of OpenSSL on the platform. Examples are `'sha256'`, `'sha512'`, etc.
* On recent releases of OpenSSL, `openssl list -digest-algorithms` will
Expand Down Expand Up @@ -1304,8 +1306,11 @@ declare module "node:crypto" {
/**
* Calculates the signature on all the data passed through using either `sign.update()` or `sign.write()`.
*
* If `privateKey` is not a `KeyObject`, this function behaves as if `privateKey` had been passed to {@link createPrivateKey}. If it is an
* object, the following additional properties can be passed:
* If `privateKey` is not a `KeyObject`, this function behaves as if
* `privateKey` had been passed to `crypto.createPrivateKey()`. When
* `privateKey` is a string, `ArrayBuffer`, `Buffer`, `TypedArray`, or
* `DataView`, it must contain PEM-encoded key material. If it is an object, the
* following additional properties can be passed:
*
* If `outputEncoding` is provided a string is returned; otherwise a `Buffer` is returned.
*
Expand Down Expand Up @@ -1375,8 +1380,11 @@ declare module "node:crypto" {
/**
* Verifies the provided data using the given `key` and `signature`.
*
* If `key` is not a `KeyObject`, this function behaves as if `key` had been passed to {@link createPublicKey}. If it is an
* object, the following additional properties can be passed:
* If `key` is not a `KeyObject`, this function behaves as if
* `key` had been passed to `crypto.createPublicKey()`. When `key` is a string,
* `ArrayBuffer`, `Buffer`, `TypedArray`, or `DataView`, it must contain
* PEM-encoded key material. If it is an object, the following additional
* properties can be passed:
*
* The `signature` argument is the previously calculated signature for the data, in
* the `signatureEncoding`.
Expand Down Expand Up @@ -2690,8 +2698,10 @@ declare module "node:crypto" {
* ML-DSA.
*
* If `key` is not a `KeyObject`, this function behaves as if `key` had been
* passed to {@link createPrivateKey}. If it is an object, the following
* additional properties can be passed:
* passed to `crypto.createPrivateKey()`. When `key` is a string, `ArrayBuffer`,
* `Buffer`, `TypedArray`, or `DataView`, it must contain PEM-encoded key
* material. If it is an object, the following additional properties can be
* passed:
*
* If the `callback` function is provided this function uses libuv's threadpool.
* @since v12.0.0
Expand All @@ -2716,8 +2726,10 @@ declare module "node:crypto" {
* ML-DSA.
*
* If `key` is not a `KeyObject`, this function behaves as if `key` had been
* passed to {@link createPublicKey}. If it is an object, the following
* additional properties can be passed:
* passed to `crypto.createPublicKey()`. When `key` is a string, `ArrayBuffer`,
* `Buffer`, `TypedArray`, or `DataView`, it must contain PEM-encoded key
* material. If it is an object, the following additional properties can be
* passed:
*
* The `signature` argument is the previously calculated signature for the `data`.
*
Expand Down
14 changes: 14 additions & 0 deletions types/node/ffi.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,20 @@ declare module "node:ffi" {
* @since v26.1.0
*/
function getRawPointer(source: ArrayBuffer | NodeJS.ArrayBufferView): bigint;
/**
* Returns the address of the current thread's `uv_loop_t` as a `bigint`.
*
* The returned address is for the current Node.js environment. In the main thread,
* this is the main thread event loop. In a worker thread, this is that worker's
* event loop.
*
* This is unsafe and dangerous. The returned pointer is only valid for the lifetime
* of the current environment. Using it after the environment exits, or from native
* code that assumes a different thread or lifetime, can crash the process or
* corrupt memory.
* @since v26.6.0
*/
function getCurrentEventLoop(): bigint;
type ReturnType = { [K in keyof DataTypeMap]: K }[keyof DataTypeMap];
type ArgumentType = Exclude<ReturnType, "void">;
interface DataTypeMap {
Expand Down
5 changes: 3 additions & 2 deletions types/node/http2.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,10 +685,11 @@ declare module "node:http2" {
* Returns a `Proxy` object that acts as a `net.Socket` (or `tls.TLSSocket`) but
* limits available methods to ones safe to use with HTTP/2.
*
* `destroy`, `emit`, `end`, `pause`, `read`, `resume`, and `write` will throw
* `emit`, `end`, `pause`, `read`, `resume`, and `write` will throw
* an error with code `ERR_HTTP2_NO_SOCKET_MANIPULATION`. See `Http2Session and Sockets` for more information.
*
* `setTimeout` method will be called on this `Http2Session`.
* `destroy`, `setTimeout`, `ref`, and `unref` methods will be called on this
* `Http2Session`.
*
* All other interactions will be routed directly to the socket.
* @since v8.4.0
Expand Down
20 changes: 16 additions & 4 deletions types/node/net.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,11 @@ declare module "node:net" {
/**
* This property represents the state of the connection as a string.
*
* * If the stream is connecting `socket.readyState` is `opening`.
* * If the stream is readable and writable, it is `open`.
* * If the stream is readable and not writable, it is `readOnly`.
* * If the stream is not readable and writable, it is `writeOnly`.
* * If the socket is connecting, `socket.readyState` is `opening`.
* * If the socket is readable and writable, it is `open`.
* * If the socket is readable and not writable, it is `readOnly`.
* * If the socket is not readable and writable, it is `writeOnly`.
* * Otherwise, it is `closed`.
* @since v0.5.0
*/
readonly readyState: SocketReadyState;
Expand All @@ -378,6 +379,12 @@ declare module "node:net" {
* @since v0.5.10
*/
readonly remotePort: number | undefined;
/**
* Reference to the server that accepted the socket. This is `null` for sockets
* that were not accepted by a server.
* @since v0.3.4
*/
readonly server: Server | null;
/**
* The socket timeout in milliseconds as set by `socket.setTimeout()`.
* It is `undefined` if a timeout has not been set.
Expand Down Expand Up @@ -486,6 +493,11 @@ declare module "node:net" {
* throw `ERR_SOCKET_HANDLE_ADOPTED`. A handle that is never adopted must be
* closed to avoid leaking the socket.
*
* When an adopted `BoundSocket` connects to a numeric IP literal, `connect(2)` is
* issued synchronously, so `socket.localAddress` is resolved once
* `socket.connect()` returns. Connection failures are still reported via a
* deferred `'error'` event.
*
* ```js
* import net from 'node:net';
*
Expand Down
3 changes: 3 additions & 0 deletions types/node/node-tests/child_process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ import { promisify } from "node:util";

{
const forked = childProcess.fork("./", ["asd"] as readonly string[], {
windowsHide: true,
windowsVerbatimArguments: true,
silent: false,
stdio: "inherit",
Expand Down Expand Up @@ -526,6 +527,8 @@ import { promisify } from "node:util";

{
const forked = childProcess.fork("./", {
windowsHide: true,
timeout: 123,
windowsVerbatimArguments: true,
silent: false,
stdio: ["inherit"],
Expand Down
Loading