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
58 changes: 45 additions & 13 deletions types/chrome/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,22 +381,53 @@ declare namespace chrome {
* Permissions: "alarms"
*/
export namespace alarms {
interface AlarmCreateInfo {
/** Length of time in minutes after which the {@link onAlarm} event should fire. */
delayInMinutes?: number | undefined;
/** If set, the onAlarm event should fire every `periodInMinutes` minutes after the initial event specified by `when` or `delayInMinutes`. If not set, the alarm will only fire once. */
periodInMinutes?: number | undefined;
/** Time at which the alarm should fire, in milliseconds past the epoch (e.g. `Date.now() + n`). */
when?: number | undefined;
}
type AlarmCreateInfo =
& {
/**
* Whether the alarm should persist across sessions (browser restarts). In Chrome, this defaults to true to match historical behavior, but you should set this explicitly to maximize compatibility across browsers.
* @since Chrome 150
*/
persistAcrossSessions?: boolean | undefined;
}
& (
| {
/** Length of time in minutes after which the {@link onAlarm} event should fire. */
delayInMinutes: number;
/** If set, the onAlarm event should fire every `periodInMinutes` minutes after the initial event specified by `when` or `delayInMinutes`. If not set, the alarm will only fire once. */
periodInMinutes?: number | undefined;
/** Time at which the alarm should fire, in milliseconds past the epoch (e.g. `Date.now() + n`). */
when?: never | undefined;
}
| {
/** Length of time in minutes after which the {@link onAlarm} event should fire. */
delayInMinutes?: number | undefined;
/** If set, the onAlarm event should fire every `periodInMinutes` minutes after the initial event specified by `when` or `delayInMinutes`. If not set, the alarm will only fire once. */
periodInMinutes: number;
/** Time at which the alarm should fire, in milliseconds past the epoch (e.g. `Date.now() + n`). */
when?: number | undefined;
}
| {
/** Length of time in minutes after which the {@link onAlarm} event should fire. */
delayInMinutes?: never | undefined;
/** If set, the onAlarm event should fire every `periodInMinutes` minutes after the initial event specified by `when` or `delayInMinutes`. If not set, the alarm will only fire once. */
periodInMinutes?: number | undefined;
/** Time at which the alarm should fire, in milliseconds past the epoch (e.g. `Date.now() + n`). */
when: number;
}
);

interface Alarm {
/** Name of this alarm. */
name: string;
/** If not null, the alarm is a repeating alarm and will fire again in `periodInMinutes` minutes. */
periodInMinutes?: number;
/**
* Whether the alarm should persist across sessions (browser restarts).
* @since Chrome 150
*/
persistAcrossSessions: boolean;
/** Time at which this alarm was scheduled to fire, in milliseconds past the epoch (e.g. `Date.now() + n`). For performance reasons, the alarm may have been delayed an arbitrary amount beyond this. */
scheduledTime: number;
/** Name of this alarm. */
name: string;
}

/**
Expand Down Expand Up @@ -7604,23 +7635,24 @@ declare namespace chrome {
* Creates a new offscreen document for the extension.
* @param parameters The parameters describing the offscreen document to create.
*
* Can return its result via Promise in Manifest V3.
* Can return its result via Promise.
*/
function createDocument(parameters: CreateParameters): Promise<void>;
function createDocument(parameters: CreateParameters, callback: () => void): void;

/**
* Closes the currently-open offscreen document for the extension.
*
* Can return its result via Promise in Manifest V3.
* Can return its result via Promise.
*/
function closeDocument(): Promise<void>;
function closeDocument(callback: () => void): void;

/**
* Determines whether the extension has an active document.
*
* Can return its result via Promise in Manifest V3.
* Can return its result via Promise.
* @since Chrome 150
*/
function hasDocument(): Promise<boolean>;
function hasDocument(callback: (result: boolean) => void): void;
Expand Down
9 changes: 9 additions & 0 deletions types/chrome/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2587,12 +2587,17 @@ async function testAlarms() {
delayInMinutes: 1,
periodInMinutes: 1,
when: 1,
persistAcrossSessions: true,
};

chrome.alarms.create(alarmCreateInfo); // $ExpectType Promise<void>
chrome.alarms.create("name", alarmCreateInfo); // $ExpectType Promise<void>
chrome.alarms.create(alarmCreateInfo, () => {}); // $ExpectType void
chrome.alarms.create("name", alarmCreateInfo, () => {}); // $ExpectType void
// @ts-expect-error Must set at least one of when, delayInMinutes, or periodInMinutes.
chrome.alarms.create("name", { persistAcrossSessions: true }, () => {});
// @ts-expect-error Cannot set both when and delayInMinutes.
chrome.alarms.create("name", { when: 1, delayInMinutes: 1 }, () => {});
// @ts-expect-error
chrome.alarms.create("name", alarmCreateInfo, () => {}).then(() => {});

Expand All @@ -2601,6 +2606,7 @@ async function testAlarms() {
alarm.name; // $ExpectType string
alarm.periodInMinutes; // $ExpectType number | undefined
alarm.scheduledTime; // $ExpectType number
alarm.persistAcrossSessions; // $ExpectType boolean
});
// @ts-expect-error
chrome.alarms.getAll(() => {}).then(() => {});
Expand Down Expand Up @@ -2631,13 +2637,15 @@ async function testAlarms() {
alarm.name; // $ExpectType string
alarm.periodInMinutes; // $ExpectType number | undefined
alarm.scheduledTime; // $ExpectType number
alarm.persistAcrossSessions; // $ExpectType boolean
});
chrome.alarms.get("name", (alarm) => { // $ExpectType void
alarm; // $ExpectType Alarm | undefined
if (!alarm) return;
alarm.name; // $ExpectType string
alarm.periodInMinutes; // $ExpectType number | undefined
alarm.scheduledTime; // $ExpectType number
alarm.persistAcrossSessions; // $ExpectType boolean
});
// @ts-expect-error
chrome.alarms.get("name", () => {}).then(() => {});
Expand All @@ -2646,6 +2654,7 @@ async function testAlarms() {
alarm.name; // $ExpectType string
alarm.periodInMinutes; // $ExpectType number | undefined
alarm.scheduledTime; // $ExpectType number
alarm.persistAcrossSessions; // $ExpectType boolean
});
}

Expand Down
4 changes: 0 additions & 4 deletions types/custom-functions-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
"name": "OfficeDev",
"githubUsername": "OfficeDev"
},
{
"name": "David Chesnut",
"githubUsername": "davidchesnut"
},
{
"name": "Alex Jerabek",
"githubUsername": "AlexJerabek"
Expand Down
2 changes: 1 addition & 1 deletion types/cyclonedx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"private": true,
"name": "@types/cyclonedx",
"version": "1.4.9999",
"nonNpm": true,
"nonNpm": "conflict",
"nonNpmDescription": "cyclonedx",
"projects": [
"https://github.com/CycloneDX/specification"
Expand Down
5 changes: 5 additions & 0 deletions types/hotwired__turbo/hotwired__turbo-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ turboFrame.loading = "slow";

turboFrame.reload().catch(console.error);

// $ExpectType string | null
turboFrame.src;
turboFrame.src = "/messages";
turboFrame.src = null;

const turboStream = document.querySelector("turbo-stream")!;

// $ExpectType StreamElement
Expand Down
2 changes: 1 addition & 1 deletion types/hotwired__turbo/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export class FrameElement extends HTMLElement {
src: string;
src: string | null;
disabled: boolean;
loading: "eager" | "lazy";
loaded: Promise<void>;
Expand Down
2 changes: 2 additions & 0 deletions types/multer/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ declare namespace multer {
fieldSize?: number | undefined;
/** Maximum number of non-file form fields. (Default: Infinity) */
fields?: number | undefined;
/** Maximum number of nesting levels for field names, e.g. `a[b][c]` has 2 levels. (Default: Infinity) */
fieldNestingDepth?: number | undefined;
/** Maximum size of each file in bytes. (Default: Infinity) */
fileSize?: number | undefined;
/** Maximum number of file fields. (Default: Infinity) */
Expand Down
17 changes: 17 additions & 0 deletions types/multer/multer-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ const upload_with_defParamCharset = multer({
upload_with_defParamCharset; // $ExpectType Multer
assert.strictEqual(upload_with_defParamCharset.constructor.name, "Multer");

const upload_with_limits = multer({
dest: "uploads/",
limits: {
fieldNameSize: 100,
fieldSize: 1048576,
fields: 10,
fieldNestingDepth: 2,
fileSize: Infinity,
files: Infinity,
parts: Infinity,
headerPairs: 2000,
},
});

upload_with_limits; // $ExpectType Multer
assert.strictEqual(upload_with_limits.constructor.name, "Multer");

const app = express();

app.post(
Expand Down
2 changes: 1 addition & 1 deletion types/multer/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@types/multer",
"version": "2.1.9999",
"version": "2.2.9999",
"projects": [
"https://github.com/expressjs/multer"
],
Expand Down
5 changes: 5 additions & 0 deletions types/namespace-emitter/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*
!**/*.d.ts
!**/*.d.cts
!**/*.d.mts
!**/*.d.*.ts
72 changes: 72 additions & 0 deletions types/namespace-emitter/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
declare namespace createNamespaceEmitter {
type Listener = (
this: Listener & { event: string },
arg1?: any,
arg2?: any,
arg3?: any,
arg4?: any,
arg5?: any,
arg6?: any,
) => void;

interface Emitter {
/**
* Emit an event. Optionally namespace the event. Handlers are fired in the order in which they were added with exact matches taking precedence. Separate the namespace and event with a `:`
*
* @param event the name of the event, with optional namespace
* @param data up to 6 arguments that are passed to the event listener
* @example
* emitter.emit('example')
* emitter.emit('demo:test')
* emitter.emit('data', { example: true }, 'a string', 1)
*/
emit(event: string, arg1?: any, arg2?: any, arg3?: any, arg4?: any, arg5?: any, arg6?: any): void;

/**
* Create en event listener.
*
* @example
* emitter.on('example', function () {})
* emitter.on('demo', function () {})
*/
on(event: string, listener: Listener): void;

/**
* Create en event listener that fires once.
*
* @example
* emitter.once('example', function () {})
* emitter.once('demo', function () {})
*/
once(event: string, listener: Listener): void;

/**
* Stop listening to an event. Stop all listeners on an event by only passing the event name. Stop a single listener by passing that event handler as a callback.
* You must be explicit about what will be unsubscribed: `emitter.off('demo')` will unsubscribe an `emitter.on('demo')` listener,
* `emitter.off('demo:example')` will unsubscribe an `emitter.on('demo:example')` listener
*
* @example
* emitter.off('example')
* emitter.off('demo', function () {})
*/
off(event: string, listener?: Listener): void;
}
}

/**
* Create an event emitter with namespaces
*
* @example
* var emitter = require('./index')()
*
* emitter.on('*', function () {
* console.log('all events emitted', this.event)
* })
*
* emitter.on('example', function () {
* console.log('example event emitted')
* })
*/
declare function createNamespaceEmitter(): createNamespaceEmitter.Emitter;

export = createNamespaceEmitter;
66 changes: 66 additions & 0 deletions types/namespace-emitter/namespace-emitter-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import createNamespaceEmitter = require("namespace-emitter");

declare namespace console {
function log(...args: unknown[]): void;
}

const emitter = createNamespaceEmitter();

// readme

emitter.on("*", function() {
console.log("all events emitted", this.event);
});

emitter.on("example", function() {
console.log("example event emitted");
});

emitter.emit("example");

emitter.on("demo", function() {
console.log("multiple events with `demo` namespace emitted", this.event);
});

emitter.emit("demo:cool");
emitter.emit("demo:awesome");
emitter.emit("demo:great");

// everything else

emitter.emit("a", {});
emitter.emit("b", {}, 1);
emitter.emit("c", {}, 1, "");
emitter.emit("d", {}, 1, "", null);
emitter.emit("e", {}, 1, "", null, true);
emitter.emit("f", {}, 1, "", null, true, undefined);
// @ts-expect-error https://github.com/sethvincent/namespace-emitter/blob/master/index.js#L29
emitter.emit("g", {}, 1, "", null, true, undefined, {});

emitter.on("a", (arg1) => {});
emitter.on("b", (arg1, arg2) => {});
emitter.on("c", (arg1, arg2, arg3) => {});
emitter.on("d", (arg1, arg2, arg3, arg4) => {});
emitter.on("e", (arg1, arg2, arg3, arg4, arg5) => {});
emitter.on("f", (arg1, arg2, arg3, arg4, arg5, arg6) => {});
// @ts-expect-error https://github.com/sethvincent/namespace-emitter/blob/master/index.js#L29
emitter.on("g", (arg1, arg2, arg3, arg4, arg5, arg6, arg7) => {});

emitter.once("a", (arg1) => {});
emitter.once("b", (arg1, arg2) => {});
emitter.once("c", (arg1, arg2, arg3) => {});
emitter.once("d", (arg1, arg2, arg3, arg4) => {});
emitter.once("e", (arg1, arg2, arg3, arg4, arg5) => {});
emitter.once("f", (arg1, arg2, arg3, arg4, arg5, arg6) => {});
// @ts-expect-error https://github.com/sethvincent/namespace-emitter/blob/master/index.js#L29
emitter.once("g", (arg1, arg2, arg3, arg4, arg5, arg6, arg7) => {});

emitter.off("a", (arg1) => {});
emitter.off("b", (arg1, arg2) => {});
emitter.off("c", (arg1, arg2, arg3) => {});
emitter.off("d", (arg1, arg2, arg3, arg4) => {});
emitter.off("e", (arg1, arg2, arg3, arg4, arg5) => {});
emitter.off("f", (arg1, arg2, arg3, arg4, arg5, arg6) => {});
// @ts-expect-error https://github.com/sethvincent/namespace-emitter/blob/master/index.js#L29
emitter.off("g", (arg1, arg2, arg3, arg4, arg5, arg6, arg7) => {});
emitter.off("h");
17 changes: 17 additions & 0 deletions types/namespace-emitter/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"private": true,
"name": "@types/namespace-emitter",
"version": "2.0.9999",
"projects": [
"https://github.com/sethvincent/namespace-emitter#readme"
],
"devDependencies": {
"@types/namespace-emitter": "workspace:."
},
"owners": [
{
"name": "Remco Haszing",
"githubUsername": "remcohaszing"
}
]
}
Loading