Define window.scheduler as non-optional

We used the wicg-task-scheduling types for `window.scheduler` but it
types it as optional - this is true for the general case but because we
are in Chrome we know it exists.

Unfortunately you cannot override the member from optional or not on
`Window`, so this CL removes the use of the
`@types/wicg-task-scheduling` package and reuses the code inline with
the extension to the `Window` interface making it always present.

Bug: none
Change-Id: I8399d3477f89f88e758ed31399c6256fcbd31de9
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6393155
Auto-Submit: Jack Franklin <jacktfranklin@chromium.org>
Reviewed-by: Connor Clark <cjamcl@chromium.org>
Commit-Queue: Connor Clark <cjamcl@chromium.org>
This commit is contained in:
Jack Franklin
2025-03-25 12:28:00 -07:00
committed by Devtools-frontend LUCI CQ
parent 3465c96d88
commit db52fce504
9 changed files with 50 additions and 88 deletions
+50
View File
@@ -6,3 +6,53 @@ declare module '*.css.js' {
const styles: {cssText: string};
export default styles;
}
// Types for the Scheduler API.
// These are taken from
// https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/wicg-task-scheduling
// but modified because within Chrome we can use the API without worrying that
// it is undefined.
// This code is licensed under the MIT license
/**
* MIT License
* Copyright (c) Microsoft Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
*/
type PostTaskPriority = 'user-blocking'|'user-visible'|'background';
interface PostTaskOptions {
priority?: PostTaskPriority;
signal?: AbortSignal;
delay?: number;
}
interface Scheduler {
yield(): Promise<void>;
postTask<T>(callback: () => T): Promise<T>;
postTask<T>(callback: () => T, options: PostTaskOptions): Promise<T>;
}
interface Window {
readonly scheduler: Scheduler;
}
interface WorkerGlobalScope {
readonly scheduler?: Scheduler;
}
-6
View File
@@ -1211,12 +1211,6 @@
"dev": true,
"license": "MIT"
},
"node_modules/@types/wicg-task-scheduling": {
"version": "2024.1.0",
"resolved": "https://registry.npmjs.org/@types/wicg-task-scheduling/-/wicg-task-scheduling-2024.1.0.tgz",
"integrity": "sha512-9g5QVDU8Na3P6rPMbyYx5pS8UpGDfzys8T7Xq5HMTbI7elSq/YioGbBVAh2u67JGNTThZ3o9PK0/qBvaVOYPYQ==",
"dev": true
},
"node_modules/@types/yargs": {
"version": "17.0.33",
"resolved": "https://npm.skia.org/chrome-devtools/@types%2fyargs/-/yargs-17.0.33.tgz",
-21
View File
@@ -1,21 +0,0 @@
MIT License
Copyright (c) Microsoft Corporation.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE
-21
View File
@@ -1,21 +0,0 @@
type PostTaskPriority = "user-blocking" | "user-visible" | "background";
interface PostTaskOptions {
priority?: PostTaskPriority;
signal?: AbortSignal;
delay?: number;
}
interface Scheduler {
yield(): Promise<void>;
postTask<T>(callback: () => T): Promise<T>;
postTask<T>(callback: () => T, options: PostTaskOptions): Promise<T>;
}
interface Window {
readonly scheduler?: Scheduler;
}
interface WorkerGlobalScope {
readonly scheduler?: Scheduler;
}
-27
View File
@@ -1,27 +0,0 @@
{
"name": "@types/wicg-task-scheduling",
"version": "2024.1.0",
"description": "TypeScript definitions for wicg-task-scheduling",
"homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/wicg-task-scheduling",
"license": "MIT",
"contributors": [
{
"name": "Rob Paveza",
"githubUsername": "robpaveza",
"url": "https://github.com/robpaveza"
}
],
"main": "",
"types": "index.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/DefinitelyTyped/DefinitelyTyped.git",
"directory": "types/wicg-task-scheduling"
},
"scripts": {},
"dependencies": {},
"peerDependencies": {},
"typesPublisherContentHash": "795a17db278225c59913a6c05c0a7bd6eb31fb8721f3c981b42e73305519586c",
"typeScriptVersion": "5.0",
"nonNpm": true
}
-7
View File
@@ -23,7 +23,6 @@
"@types/node": "22.10.7",
"@types/sinon": "17.0.3",
"@types/webidl2": "23.13.6",
"@types/wicg-task-scheduling": "2024.1.0",
"@types/yargs": "17.0.33",
"@typescript-eslint/eslint-plugin": "8.26.0",
"@typescript-eslint/parser": "8.26.0",
@@ -1972,12 +1971,6 @@
"dev": true,
"license": "MIT"
},
"node_modules/@types/wicg-task-scheduling": {
"version": "2024.1.0",
"resolved": "https://registry.npmjs.org/@types/wicg-task-scheduling/-/wicg-task-scheduling-2024.1.0.tgz",
"integrity": "sha512-9g5QVDU8Na3P6rPMbyYx5pS8UpGDfzys8T7Xq5HMTbI7elSq/YioGbBVAh2u67JGNTThZ3o9PK0/qBvaVOYPYQ==",
"dev": true
},
"node_modules/@types/yargs": {
"version": "17.0.33",
"resolved": "https://npm.skia.org/chrome-devtools/@types%2fyargs/-/yargs-17.0.33.tgz",
-1
View File
@@ -50,7 +50,6 @@
"@types/node": "22.10.7",
"@types/sinon": "17.0.3",
"@types/webidl2": "23.13.6",
"@types/wicg-task-scheduling": "2024.1.0",
"@types/yargs": "17.0.33",
"@typescript-eslint/eslint-plugin": "8.26.0",
"@typescript-eslint/parser": "8.26.0",
-3
View File
@@ -45,9 +45,6 @@ GLOBAL_TYPESCRIPT_DEFINITION_FILES = [
'global_defs.d.ts'),
# Types for W3C FileSystem API
path.join(NODE_MODULES_DIRECTORY, '@types', 'filesystem', 'index.d.ts'),
# Types for wicg task scheduling API
path.join(NODE_MODULES_DIRECTORY, '@types', 'wicg-task-scheduling',
'index.d.ts'),
]
logging.basicConfig(
-2
View File
@@ -65,8 +65,6 @@ template("ts_library") {
devtools_location_prepend + "front_end/legacy/legacy-defs.d.ts",
devtools_location_prepend + "front_end/global_typings/global_defs.d.ts",
devtools_location_prepend + "node_modules/@types/filesystem/index.d.ts",
devtools_location_prepend +
"node_modules/@types/wicg-task-scheduling/index.d.ts",
]
# When use_remoteexec=true, node actions run on remote Linux worker.