Skip to content

Commit f2b36c6

Browse files
authored
🤖 Merge PR DefinitelyTyped#73783 [chrome] update readingList namespace by @erwanjugand
1 parent 7bc63a4 commit f2b36c6

File tree

2 files changed

+55
-111
lines changed

2 files changed

+55
-111
lines changed

types/chrome/index.d.ts

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8503,57 +8503,48 @@ declare namespace chrome {
85038503

85048504
/**
85058505
* Adds an entry to the reading list if it does not exist.
8506-
* @since Chrome 120, MV3
8506+
*
8507+
* Can return its result via Promise.
85078508
* @param entry The entry to add to the reading list.
8508-
* @param callback
85098509
*/
85108510
export function addEntry(entry: AddEntryOptions): Promise<void>;
85118511
export function addEntry(entry: AddEntryOptions, callback: () => void): void;
85128512

85138513
/**
85148514
* Retrieves all entries that match the `QueryInfo` properties. Properties that are not provided will not be matched.
8515-
* @since Chrome 120, MV3
8515+
*
8516+
* Can return its result via Promise.
85168517
* @param info The properties to search for.
8517-
* @param callback
85188518
*/
85198519
export function query(info: QueryInfo): Promise<ReadingListEntry[]>;
85208520
export function query(info: QueryInfo, callback: (entries: ReadingListEntry[]) => void): void;
85218521

85228522
/**
85238523
* Removes an entry from the reading list if it exists.
8524-
* @since Chrome 120, MV3
8524+
*
8525+
* Can return its result via Promise.
85258526
* @param info The entry to remove from the reading list.
8526-
* @param callback
85278527
*/
85288528
export function removeEntry(info: RemoveOptions): Promise<void>;
85298529
export function removeEntry(info: RemoveOptions, callback: () => void): void;
85308530

85318531
/**
85328532
* Updates a reading list entry if it exists.
8533-
* @since Chrome 120, MV3
8533+
*
8534+
* Can return its result via Promise.
85348535
* @param info The entry to update.
8535-
* @param callback
85368536
*/
85378537
export function updateEntry(info: UpdateEntryOptions): Promise<void>;
85388538
export function updateEntry(info: UpdateEntryOptions, callback: () => void): void;
85398539

8540-
/**
8541-
* Triggered when a ReadingListEntry is added to the reading list.
8542-
* @since Chrome 120, MV3
8543-
*/
8544-
export const onEntryAdded: chrome.events.Event<(entry: ReadingListEntry) => void>;
8540+
/** Triggered when a `ReadingListEntry` is added to the reading list. */
8541+
export const onEntryAdded: events.Event<(entry: ReadingListEntry) => void>;
85458542

8546-
/**
8547-
* Triggered when a ReadingListEntry is removed from the reading list.
8548-
* @since Chrome 120, MV3
8549-
*/
8550-
export const onEntryRemoved: chrome.events.Event<(entry: ReadingListEntry) => void>;
8543+
/** Triggered when a `ReadingListEntry` is removed from the reading list. */
8544+
export const onEntryRemoved: events.Event<(entry: ReadingListEntry) => void>;
85518545

8552-
/**
8553-
* Triggered when a ReadingListEntry is updated in the reading list.
8554-
* @since Chrome 120, MV3
8555-
*/
8556-
export const onEntryUpdated: chrome.events.Event<(entry: ReadingListEntry) => void>;
8546+
/** Triggered when a `ReadingListEntry` is updated in the reading list. */
8547+
export const onEntryUpdated: events.Event<(entry: ReadingListEntry) => void>;
85578548
}
85588549

85598550
////////////////////

types/chrome/test/index.ts

Lines changed: 41 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -7254,111 +7254,64 @@ function testPrivacy() {
72547254

72557255
// https://developer.chrome.com/docs/extensions/reference/api/readingList
72567256
function testReadingList() {
7257-
const {
7258-
addEntry,
7259-
query,
7260-
removeEntry,
7261-
updateEntry,
7262-
onEntryAdded,
7263-
onEntryRemoved,
7264-
onEntryUpdated,
7265-
} = chrome.readingList;
7266-
7267-
const testAddEntry = () => {
7268-
const entry = {
7269-
hasBeenRead: true,
7270-
title: "title",
7271-
url: "url",
7272-
};
7273-
7274-
// @ts-expect-error
7275-
addEntry();
7276-
7277-
// @ts-expect-error
7278-
addEntry({});
7279-
addEntry(entry); // $ExpectType Promise<void>
7280-
7281-
// @ts-expect-error
7282-
addEntry({}, () => {});
7283-
addEntry(entry, () => {}); // $ExpectType void
7284-
7285-
// @ts-expect-error
7286-
addEntry(entry, () => {}).then(() => {});
7257+
const entry: chrome.readingList.AddEntryOptions = {
7258+
hasBeenRead: true,
7259+
title: "title",
7260+
url: "url",
72877261
};
72887262

7289-
const testQuery = () => {
7290-
const info = {
7291-
hasBeenRead: true,
7292-
title: "title",
7293-
url: "url",
7294-
};
7295-
7296-
// @ts-expect-error
7297-
query();
7298-
7299-
query({}); // $ExpectType Promise<ReadingListEntry[]>
7300-
query(info); // $ExpectType Promise<ReadingListEntry[]>
7301-
7302-
query({}, () => {}); // $ExpectType void
7303-
query(info, () => {}); // $ExpectType void
7263+
chrome.readingList.addEntry(entry); // $ExpectType Promise<void>
7264+
chrome.readingList.addEntry(entry, () => void 0); // $ExpectType void
7265+
// @ts-expect-error
7266+
chrome.readingList.addEntry(entry, () => {}).then(() => {});
73047267

7305-
// @ts-expect-error
7306-
query(info, () => {}).then(() => {});
7268+
const queryInfo: chrome.readingList.QueryInfo = {
7269+
hasBeenRead: true,
7270+
title: "title",
7271+
url: "url",
73077272
};
73087273

7309-
const testRemoveEntry = () => {
7310-
const info = {
7311-
url: "url",
7312-
};
7313-
7314-
// @ts-expect-error
7315-
removeEntry();
7316-
7317-
// @ts-expect-error
7318-
removeEntry({});
7319-
removeEntry(info); // $ExpectType Promise<void>
7320-
7321-
// @ts-expect-error
7322-
removeEntry({}, () => {});
7323-
removeEntry(info, () => {}); // $ExpectType void
7274+
chrome.readingList.query(queryInfo); // $ExpectType Promise<ReadingListEntry[]>
7275+
chrome.readingList.query(queryInfo, ([entry]) => { // $ExpectType void
7276+
entry; // $ExpectType ReadingListEntry
7277+
entry.creationTime; // $ExpectType number
7278+
entry.hasBeenRead; // $ExpectType boolean
7279+
entry.lastUpdateTime; // $ExpectType number
7280+
entry.title; // $ExpectType string
7281+
entry.url; // $ExpectType string
7282+
});
7283+
// @ts-expect-error
7284+
chrome.readingList.query(queryInfo, () => {}).then(() => {});
73247285

7325-
// @ts-expect-error
7326-
removeEntry(info, () => {}).then(() => {});
7286+
const removeInfo: chrome.readingList.RemoveOptions = {
7287+
url: "url",
73277288
};
73287289

7329-
const testUpdateEntry = () => {
7330-
const info = {
7331-
hasBeenRead: true,
7332-
title: "title",
7333-
url: "url",
7334-
};
7335-
7336-
// @ts-expect-error
7337-
updateEntry();
7338-
7339-
// @ts-expect-error
7340-
updateEntry({});
7341-
updateEntry({ url: "url" }); // $ExpectType Promise<void>
7342-
updateEntry(info); // $ExpectType Promise<void>
7343-
7344-
// @ts-expect-error
7345-
updateEntry({}, () => {});
7346-
updateEntry({ url: "url" }, () => {}); // $ExpectType void
7347-
updateEntry(info, () => {}); // $ExpectType void
7290+
chrome.readingList.removeEntry(removeInfo); // $ExpectType Promise<void>
7291+
chrome.readingList.removeEntry(removeInfo, () => void 0); // $ExpectType void
7292+
// @ts-expect-error
7293+
chrome.readingList.removeEntry(removeInfo, () => {}).then(() => {});
73487294

7349-
// @ts-expect-error
7350-
updateEntry(info, () => {}).then(() => {});
7295+
const updateInfo: chrome.readingList.UpdateEntryOptions = {
7296+
hasBeenRead: true,
7297+
title: "title",
7298+
url: "url",
73517299
};
73527300

7353-
checkChromeEvent(onEntryAdded, (entry) => {
7301+
chrome.readingList.updateEntry(updateInfo); // $ExpectType Promise<void>
7302+
chrome.readingList.updateEntry(updateInfo, () => void 0); // $ExpectType void
7303+
// @ts-expect-error
7304+
chrome.readingList.updateEntry(updateInfo, () => {}).then(() => {});
7305+
7306+
checkChromeEvent(chrome.readingList.onEntryAdded, (entry) => {
73547307
entry; // $ExpectType ReadingListEntry
73557308
});
73567309

7357-
checkChromeEvent(onEntryRemoved, (entry) => {
7310+
checkChromeEvent(chrome.readingList.onEntryRemoved, (entry) => {
73587311
entry; // $ExpectType ReadingListEntry
73597312
});
73607313

7361-
checkChromeEvent(onEntryUpdated, (entry) => {
7314+
checkChromeEvent(chrome.readingList.onEntryUpdated, (entry) => {
73627315
entry; // $ExpectType ReadingListEntry
73637316
});
73647317
}

0 commit comments

Comments
 (0)