Skip to content

Commit db52fce

Browse files
jackfranklinDevtools-frontend LUCI CQ
authored andcommitted
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 <[email protected]> Reviewed-by: Connor Clark <[email protected]> Commit-Queue: Connor Clark <[email protected]>
1 parent 3465c96 commit db52fce

File tree

9 files changed

+50
-88
lines changed

9 files changed

+50
-88
lines changed

front_end/global_typings/global_defs.d.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,53 @@ declare module '*.css.js' {
66
const styles: {cssText: string};
77
export default styles;
88
}
9+
10+
// Types for the Scheduler API.
11+
// These are taken from
12+
// https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/wicg-task-scheduling
13+
// but modified because within Chrome we can use the API without worrying that
14+
// it is undefined.
15+
// This code is licensed under the MIT license
16+
/**
17+
* MIT License
18+
* Copyright (c) Microsoft Corporation.
19+
*
20+
* Permission is hereby granted, free of charge, to any person obtaining a copy
21+
* of this software and associated documentation files (the "Software"), to deal
22+
* in the Software without restriction, including without limitation the rights
23+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
24+
* copies of the Software, and to permit persons to whom the Software is
25+
* furnished to do so, subject to the following conditions:
26+
*
27+
* The above copyright notice and this permission notice shall be included in all
28+
* copies or substantial portions of the Software.
29+
*
30+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
33+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
34+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
35+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36+
* SOFTWARE
37+
*/
38+
type PostTaskPriority = 'user-blocking'|'user-visible'|'background';
39+
40+
interface PostTaskOptions {
41+
priority?: PostTaskPriority;
42+
signal?: AbortSignal;
43+
delay?: number;
44+
}
45+
46+
interface Scheduler {
47+
yield(): Promise<void>;
48+
postTask<T>(callback: () => T): Promise<T>;
49+
postTask<T>(callback: () => T, options: PostTaskOptions): Promise<T>;
50+
}
51+
52+
interface Window {
53+
readonly scheduler: Scheduler;
54+
}
55+
56+
interface WorkerGlobalScope {
57+
readonly scheduler?: Scheduler;
58+
}

node_modules/.package-lock.json

Lines changed: 0 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@types/wicg-task-scheduling/LICENSE

Lines changed: 0 additions & 21 deletions
This file was deleted.

node_modules/@types/wicg-task-scheduling/index.d.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

node_modules/@types/wicg-task-scheduling/package.json

Lines changed: 0 additions & 27 deletions
This file was deleted.

package-lock.json

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
"@types/node": "22.10.7",
5151
"@types/sinon": "17.0.3",
5252
"@types/webidl2": "23.13.6",
53-
"@types/wicg-task-scheduling": "2024.1.0",
5453
"@types/yargs": "17.0.33",
5554
"@typescript-eslint/eslint-plugin": "8.26.0",
5655
"@typescript-eslint/parser": "8.26.0",

scripts/build/typescript/ts_library.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@
4545
'global_defs.d.ts'),
4646
# Types for W3C FileSystem API
4747
path.join(NODE_MODULES_DIRECTORY, '@types', 'filesystem', 'index.d.ts'),
48-
# Types for wicg task scheduling API
49-
path.join(NODE_MODULES_DIRECTORY, '@types', 'wicg-task-scheduling',
50-
'index.d.ts'),
5148
]
5249

5350
logging.basicConfig(

scripts/build/typescript/typescript.gni

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ template("ts_library") {
6565
devtools_location_prepend + "front_end/legacy/legacy-defs.d.ts",
6666
devtools_location_prepend + "front_end/global_typings/global_defs.d.ts",
6767
devtools_location_prepend + "node_modules/@types/filesystem/index.d.ts",
68-
devtools_location_prepend +
69-
"node_modules/@types/wicg-task-scheduling/index.d.ts",
7068
]
7169

7270
# When use_remoteexec=true, node actions run on remote Linux worker.

0 commit comments

Comments
 (0)