Skip to content

Commit 228c354

Browse files
authored
Add types for js globals (#31586)
Adds types for `window.config` and jQuery/htmx globals, eliminating 48 `tsc` errors.
1 parent 1b0ccf4 commit 228c354

File tree

4 files changed

+48
-4
lines changed

4 files changed

+48
-4
lines changed

.eslintrc.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ overrides:
4747
- files: ["web_src/**/*"]
4848
globals:
4949
__webpack_public_path__: true
50-
htmx: true
5150
process: false # https://github.com/webpack/webpack/issues/15833
5251
- files: ["web_src/**/*", "docs/**/*"]
5352
env:
@@ -58,7 +57,15 @@ overrides:
5857
worker: true
5958
rules:
6059
no-restricted-globals: [2, addEventListener, blur, close, closed, confirm, defaultStatus, defaultstatus, error, event, external, find, focus, frameElement, frames, history, innerHeight, innerWidth, isFinite, isNaN, length, locationbar, menubar, moveBy, moveTo, name, onblur, onerror, onfocus, onload, onresize, onunload, open, opener, opera, outerHeight, outerWidth, pageXOffset, pageYOffset, parent, print, removeEventListener, resizeBy, resizeTo, screen, screenLeft, screenTop, screenX, screenY, scroll, scrollbars, scrollBy, scrollTo, scrollX, scrollY, status, statusbar, stop, toolbar, top]
61-
- files: ["*.config.*", "**/*.d.ts"]
60+
- files: ["*.config.*"]
61+
rules:
62+
i/no-unused-modules: [0]
63+
- files: ["**/*.d.ts"]
64+
rules:
65+
i/no-unused-modules: [0]
66+
"@typescript-eslint/consistent-type-definitions": [0]
67+
"@typescript-eslint/consistent-type-imports": [0]
68+
- files: ["web_src/js/types.ts"]
6269
rules:
6370
i/no-unused-modules: [0]
6471
- files: ["**/*.test.*", "web_src/js/test/setup.ts"]

types.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,17 @@ declare module '*.svg' {
22
const value: string;
33
export default value;
44
}
5+
6+
declare let __webpack_public_path__: string;
7+
8+
interface Window {
9+
config: import('./web_src/js/types.ts').Config;
10+
$: typeof import('@types/jquery'),
11+
jQuery: typeof import('@types/jquery'),
12+
htmx: typeof import('htmx.org'),
13+
}
14+
15+
declare module 'htmx.org/dist/htmx.esm.js' {
16+
const value = await import('htmx.org');
17+
export default value;
18+
}

web_src/js/htmx.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import {showErrorToast} from './modules/toast.ts';
44
import 'idiomorph/dist/idiomorph-ext.js';
55

66
// https://htmx.org/reference/#config
7-
htmx.config.requestClass = 'is-loading';
8-
htmx.config.scrollIntoViewOnBoost = false;
7+
window.htmx.config.requestClass = 'is-loading';
8+
window.htmx.config.scrollIntoViewOnBoost = false;
99

1010
// https://htmx.org/events/#htmx:sendError
1111
document.body.addEventListener('htmx:sendError', (event) => {

web_src/js/types.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
export type MentionValue = {
2+
key: string,
3+
value: string,
4+
name: string,
5+
fullname: string,
6+
avatar: string,
7+
}
8+
9+
export type Config = {
10+
appUrl: string,
11+
appSubUrl: string,
12+
assetVersionEncoded: string,
13+
assetUrlPrefix: string,
14+
runModeIsProd: boolean,
15+
customEmojis: Record<string, string>,
16+
csrfToken: string,
17+
pageData: Record<string, any>,
18+
notificationSettings: Record<string, any>,
19+
enableTimeTracking: boolean,
20+
mentionValues?: MentionValue[],
21+
mermaidMaxSourceCharacters: number,
22+
i18n: Record<string, string>,
23+
}

0 commit comments

Comments
 (0)