Skip to content

Commit 356d609

Browse files
authored
🤖 Merge PR DefinitelyTyped#72665 [chrome] update TabGroups namespace by @erwanjugand
1 parent f5006bf commit 356d609

File tree

2 files changed

+156
-106
lines changed

2 files changed

+156
-106
lines changed

types/chrome/index.d.ts

Lines changed: 53 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -12226,131 +12226,111 @@ declare namespace chrome {
1222612226
*/
1222712227
export namespace tabGroups {
1222812228
/** An ID that represents the absence of a group. */
12229-
export var TAB_GROUP_ID_NONE: -1;
12229+
export const TAB_GROUP_ID_NONE: -1;
1223012230

12231-
export type ColorEnum = "grey" | "blue" | "red" | "yellow" | "green" | "pink" | "purple" | "cyan" | "orange";
12231+
/** The group's color. */
12232+
export enum Color {
12233+
BLUE = "blue",
12234+
CYAN = "cyan",
12235+
GREEN = "green",
12236+
GREY = "grey",
12237+
ORANGE = "orange",
12238+
PINK = "pink",
12239+
PURPLE = "purple",
12240+
RED = "red",
12241+
YELLOW = "yellow",
12242+
}
1223212243

1223312244
export interface TabGroup {
1223412245
/** Whether the group is collapsed. A collapsed group is one whose tabs are hidden. */
1223512246
collapsed: boolean;
1223612247
/** The group's color. */
12237-
color: ColorEnum;
12248+
color: `${Color}`;
1223812249
/** The ID of the group. Group IDs are unique within a browser session. */
1223912250
id: number;
12240-
/** Optional. The title of the group. */
12241-
title?: string | undefined;
12251+
/** The title of the group. */
12252+
title?: string;
1224212253
/** The ID of the window that contains the group. */
1224312254
windowId: number;
1224412255
}
1224512256

1224612257
export interface MoveProperties {
12247-
/** The position to move the group to. Use -1 to place the group at the end of the window. */
12258+
/** The position to move the group to. Use `-1` to place the group at the end of the window. */
1224812259
index: number;
12249-
/** Optional. The window to move the group to. Defaults to the window the group is currently in. Note that groups can only be moved to and from windows with chrome.windows.WindowType type "normal". */
12250-
windowId?: number | undefined;
12260+
/** The window to move the group to. Defaults to the window the group is currently in. Note that groups can only be moved to and from windows with {@link windows.windowTypeEnum windows.windowType} type `"normal"`. */
12261+
windowId?: number;
1225112262
}
1225212263

1225312264
export interface QueryInfo {
12254-
/** Optional. Whether the groups are collapsed. */
12255-
collapsed?: boolean | undefined;
12256-
/** Optional. The color of the groups. */
12257-
color?: ColorEnum | undefined;
12258-
/** Optional. Match group titles against a pattern. */
12259-
title?: string | undefined;
12260-
/** Optional. The ID of the window that contains the group. */
12261-
windowId?: number | undefined;
12265+
/** Whether the groups are collapsed. */
12266+
collapsed?: boolean;
12267+
/** The color of the groups. */
12268+
color?: `${Color}`;
12269+
/** Match group titles against a pattern. */
12270+
title?: string;
12271+
/** The ID of the parent window, or {@link windows.WINDOW_ID_CURRENT} for the current window. */
12272+
windowId?: number;
1226212273
}
1226312274

1226412275
export interface UpdateProperties {
12265-
/** Optional. Whether the group should be collapsed. */
12266-
collapsed?: boolean | undefined;
12267-
/** Optional. The color of the group. */
12268-
color?: ColorEnum | undefined;
12269-
/** Optional. The title of the group. */
12270-
title?: string | undefined;
12276+
/** Whether the group should be collapsed. */
12277+
collapsed?: boolean;
12278+
/** The color of the group. */
12279+
color?: `${Color}`;
12280+
/** The title of the group. */
12281+
title?: string;
1227112282
}
1227212283

1227312284
/**
1227412285
* Retrieves details about the specified group.
12275-
* @param groupId The ID of the tab group.
12276-
* @param callback Called with the retrieved tab group.
12277-
*/
12278-
export function get(groupId: number, callback: (group: TabGroup) => void): void;
12279-
12280-
/**
12281-
* Retrieves details about the specified group.
12282-
* @param groupId The ID of the tab group.
12283-
* @return The `get` method provides its result via callback or returned as a `Promise` (MV3 only).
12286+
*
12287+
* Can return its result via Promise since Chrome 90.
1228412288
*/
1228512289
export function get(groupId: number): Promise<TabGroup>;
12290+
export function get(groupId: number, callback: (group: TabGroup) => void): void;
1228612291

1228712292
/**
1228812293
* Moves the group and all its tabs within its window, or to a new window.
1228912294
* @param groupId The ID of the group to move.
12290-
* @param moveProperties Information on how to move the group.
12291-
* @return The `move` method provides its result via callback or returned as a `Promise` (MV3 only).
12292-
*/
12293-
export function move(groupId: number, moveProperties: MoveProperties): Promise<TabGroup>;
12294-
12295-
/**
12296-
* Moves the group and all its tabs within its window, or to a new window.
12297-
* @param groupId The ID of the group to move.
12298-
* @param moveProperties Information on how to move the group.
12299-
* @param callback Optional.
12295+
*
12296+
* Can return its result via Promise since Chrome 90.
1230012297
*/
12298+
export function move(groupId: number, moveProperties: MoveProperties): Promise<TabGroup | undefined>;
1230112299
export function move(
1230212300
groupId: number,
1230312301
moveProperties: MoveProperties,
12304-
callback: (group: TabGroup) => void,
12302+
callback: (group?: TabGroup) => void,
1230512303
): void;
1230612304

1230712305
/**
1230812306
* Gets all groups that have the specified properties, or all groups if no properties are specified.
12309-
* @param queryInfo Object with search parameters.
12310-
* @param callback Called with retrieved tab groups.
12311-
*/
12312-
export function query(queryInfo: QueryInfo, callback: (result: TabGroup[]) => void): void;
12313-
12314-
/**
12315-
* Gets all groups that have the specified properties, or all groups if no properties are specified.
12316-
* @param queryInfo Object with search parameters.
12317-
* @return The `query` method provides its result via callback or returned as a `Promise` (MV3 only).
12307+
*
12308+
* Can return its result via Promise since Chrome 90.
1231812309
*/
1231912310
export function query(queryInfo: QueryInfo): Promise<TabGroup[]>;
12311+
export function query(queryInfo: QueryInfo, callback: (result: TabGroup[]) => void): void;
1232012312

1232112313
/**
12322-
* Modifies the properties of a group. Properties that are not specified in updateProperties are not modified.
12323-
* @param groupId The ID of the group to modify.
12324-
* @param updateProperties Information on how to update the group.
12325-
* @return The `update` method provides its result via callback or returned as a `Promise` (MV3 only).
12326-
*/
12327-
export function update(groupId: number, updateProperties: UpdateProperties): Promise<TabGroup>;
12328-
12329-
/**
12330-
* Modifies the properties of a group. Properties that are not specified in updateProperties are not modified.
12314+
* Modifies the properties of a group. Properties that are not specified in `updateProperties` are not modified.
1233112315
* @param groupId The ID of the group to modify.
12332-
* @param updateProperties Information on how to update the group.
12333-
* @param callback Optional.
12316+
*
12317+
* Can return its result via Promise since Chrome 90.
1233412318
*/
12319+
export function update(groupId: number, updateProperties: UpdateProperties): Promise<TabGroup | undefined>;
1233512320
export function update(
1233612321
groupId: number,
1233712322
updateProperties: UpdateProperties,
12338-
callback: (group: TabGroup) => void,
12323+
callback: (group?: TabGroup) => void,
1233912324
): void;
1234012325

12341-
export interface TabGroupCreatedEvent extends chrome.events.Event<(group: TabGroup) => void> {}
12342-
export interface TabGroupMovedEvent extends chrome.events.Event<(group: TabGroup) => void> {}
12343-
export interface TabGroupRemovedEvent extends chrome.events.Event<(group: TabGroup) => void> {}
12344-
export interface TabGroupUpdated extends chrome.events.Event<(group: TabGroup) => void> {}
12345-
1234612326
/** Fired when a group is created. */
12347-
export var onCreated: TabGroupCreatedEvent;
12327+
export const onCreated: events.Event<(group: TabGroup) => void>;
1234812328
/** Fired when a group is moved within a window. Move events are still fired for the individual tabs within the group, as well as for the group itself. This event is not fired when a group is moved between windows; instead, it will be removed from one window and created in another. */
12349-
export var onMoved: TabGroupMovedEvent;
12350-
/** Fired when a group is closed, either directly by the user or automatically because it contained zero. */
12351-
export var onRemoved: TabGroupRemovedEvent;
12329+
export const onMoved: events.Event<(group: TabGroup) => void>;
12330+
/** Fired when a group is closed, either directly by the user or automatically because it contained zero tabs. */
12331+
export const onRemoved: events.Event<(group: TabGroup) => void>;
1235212332
/** Fired when a group is updated. */
12353-
export var onUpdated: TabGroupUpdated;
12333+
export const onUpdated: events.Event<(group: TabGroup) => void>;
1235412334
}
1235512335

1235612336
////////////////////

types/chrome/test/index.ts

Lines changed: 103 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -680,33 +680,6 @@ async function testTabInterface() {
680680
tab.sessionId; // $ExpectType string | undefined
681681
}
682682

683-
// tabGroups: https://developer.chrome.com/extensions/tabGroups#
684-
async function testTabGroupInterface() {
685-
const options = { collapsed: false, title: "Test" };
686-
687-
chrome.tabGroups.query(options, tabGroups => {
688-
// $ExpectType TabGroup[]
689-
tabGroups;
690-
691-
const [tabGroup] = tabGroups;
692-
tabGroup.collapsed; // $ExpectType boolean
693-
tabGroup.color; // $ExpectType ColorEnum
694-
tabGroup.id; // $ExpectType number
695-
tabGroup.title; // $ExpectType string | undefined
696-
tabGroup.windowId; // $ExpectType number
697-
698-
tabGroup.color = "grey";
699-
tabGroup.color = "blue";
700-
tabGroup.color = "red";
701-
tabGroup.color = "yellow";
702-
tabGroup.color = "green";
703-
tabGroup.color = "pink";
704-
tabGroup.color = "purple";
705-
tabGroup.color = "cyan";
706-
tabGroup.color = "orange";
707-
});
708-
}
709-
710683
// https://developer.chrome.com/extensions/runtime#method-openOptionsPage
711684
function testOptionsPage() {
712685
chrome.runtime.openOptionsPage();
@@ -2619,12 +2592,109 @@ async function testTabs() {
26192592
chrome.tabs.onZoomChange.hasListeners(); // $ExpectType boolean
26202593
}
26212594

2622-
// https://developer.chrome.com/docs/extensions/reference/tabGroups
2623-
async function testTabGroupsForPromise() {
2624-
await chrome.tabGroups.get(0);
2625-
await chrome.tabGroups.move(0, { index: 0 });
2626-
await chrome.tabGroups.query({});
2627-
await chrome.tabGroups.update(0, {});
2595+
// https://developer.chrome.com/docs/extensions/reference/api/tabGroups
2596+
async function testTabGroup() {
2597+
chrome.tabGroups.Color.BLUE === "blue";
2598+
chrome.tabGroups.Color.CYAN === "cyan";
2599+
chrome.tabGroups.Color.GREEN === "green";
2600+
chrome.tabGroups.Color.GREY === "grey";
2601+
chrome.tabGroups.Color.ORANGE === "orange";
2602+
chrome.tabGroups.Color.PINK === "pink";
2603+
chrome.tabGroups.Color.PURPLE === "purple";
2604+
chrome.tabGroups.Color.RED === "red";
2605+
chrome.tabGroups.Color.YELLOW === "yellow";
2606+
2607+
chrome.tabGroups.TAB_GROUP_ID_NONE === -1;
2608+
2609+
const groupId = 1;
2610+
2611+
chrome.tabGroups.get(groupId); // $ExpectType Promise<TabGroup>
2612+
chrome.tabGroups.get(groupId, (group) => { // $ExpectType void
2613+
group; // $ExpectType TabGroup
2614+
});
2615+
// @ts-expect-error
2616+
chrome.tabGroups.get(() => {}).then(() => {});
2617+
2618+
const moveProperties: chrome.tabGroups.MoveProperties = {
2619+
index: 0,
2620+
windowId: 0,
2621+
};
2622+
2623+
chrome.tabGroups.move(groupId, moveProperties); // $ExpectType Promise<TabGroup | undefined>
2624+
chrome.tabGroups.move(groupId, moveProperties, (group) => { // $ExpectType void
2625+
group; // $ExpectType TabGroup | undefined
2626+
});
2627+
// @ts-expect-error
2628+
chrome.tabGroups.move(() => {}).then(() => {});
2629+
2630+
const queryInfo: chrome.tabGroups.QueryInfo = {
2631+
collapsed: false,
2632+
title: "Test",
2633+
};
2634+
2635+
chrome.tabGroups.query(queryInfo); // $ExpectType Promise<TabGroup[]>
2636+
chrome.tabGroups.query(queryInfo, (groups) => { // $ExpectType void
2637+
groups; // $ExpectType TabGroup[]
2638+
});
2639+
// @ts-expect-error
2640+
chrome.tabGroups.query(() => {}).then(() => {});
2641+
2642+
const updateProperties: chrome.tabGroups.UpdateProperties = {
2643+
collapsed: false,
2644+
title: "Test",
2645+
color: "blue",
2646+
};
2647+
2648+
chrome.tabGroups.update(groupId, updateProperties); // $ExpectType Promise<TabGroup | undefined>
2649+
chrome.tabGroups.update(groupId, updateProperties, (group) => { // $ExpectType void
2650+
group; // $ExpectType TabGroup | undefined
2651+
});
2652+
// @ts-expect-error
2653+
chrome.tabGroups.update(() => {}).then(() => {});
2654+
2655+
chrome.tabGroups.onCreated.addListener((group) => { // $ExpectType void
2656+
group; // $ExpectType TabGroup
2657+
});
2658+
chrome.tabGroups.onCreated.removeListener((group) => { // $ExpectType void
2659+
group; // $ExpectType TabGroup
2660+
});
2661+
chrome.tabGroups.onCreated.hasListener((group) => { // $ExpectType boolean
2662+
group; // $ExpectType TabGroup
2663+
});
2664+
chrome.tabGroups.onCreated.hasListeners(); // $ExpectType boolean
2665+
2666+
chrome.tabGroups.onMoved.addListener((group) => { // $ExpectType void
2667+
group; // $ExpectType TabGroup
2668+
});
2669+
chrome.tabGroups.onMoved.removeListener((group) => { // $ExpectType void
2670+
group; // $ExpectType TabGroup
2671+
});
2672+
chrome.tabGroups.onMoved.hasListener((group) => { // $ExpectType boolean
2673+
group; // $ExpectType TabGroup
2674+
});
2675+
chrome.tabGroups.onMoved.hasListeners(); // $ExpectType boolean
2676+
2677+
chrome.tabGroups.onRemoved.addListener((group) => { // $ExpectType void
2678+
group; // $ExpectType TabGroup
2679+
});
2680+
chrome.tabGroups.onRemoved.removeListener((group) => { // $ExpectType void
2681+
group; // $ExpectType TabGroup
2682+
});
2683+
chrome.tabGroups.onRemoved.hasListener((group) => { // $ExpectType boolean
2684+
group; // $ExpectType TabGroup
2685+
});
2686+
chrome.tabGroups.onRemoved.hasListeners(); // $ExpectType boolean
2687+
2688+
chrome.tabGroups.onUpdated.addListener((group) => { // $ExpectType void
2689+
group; // $ExpectType TabGroup
2690+
});
2691+
chrome.tabGroups.onUpdated.removeListener((group) => { // $ExpectType void
2692+
group; // $ExpectType TabGroup
2693+
});
2694+
chrome.tabGroups.onUpdated.hasListener((group) => { // $ExpectType boolean
2695+
group; // $ExpectType TabGroup
2696+
});
2697+
chrome.tabGroups.onUpdated.hasListeners(); // $ExpectType boolean
26282698
}
26292699

26302700
// https://developer.chrome.com/docs/extensions/reference/windows

0 commit comments

Comments
 (0)