Skip to content

Commit 184e864

Browse files
SteffenDEtozz
andauthored
use PropertyKey in hook type (#3938)
* change type definiton for unspecified keys in Hook * also use PropertyKey in HookInterface --------- Co-authored-by: Erik Johansson <[email protected]>
1 parent 08bd65d commit 184e864

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

assets/js/phoenix_live_view/live_socket.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ export default class LiveSocket {
8282
this.uploaders = opts.uploaders || {};
8383
this.loaderTimeout = opts.loaderTimeout || LOADER_TIMEOUT;
8484
this.disconnectedTimeout = opts.disconnectedTimeout || DISCONNECTED_TIMEOUT;
85+
/**
86+
* @type {ReturnType<typeof setTimeout> | null}
87+
*/
8588
this.reloadWithJitterTimer = null;
8689
this.maxReloads = opts.maxReloads || MAX_RELOADS;
8790
this.reloadJitterMin = opts.reloadJitterMin || RELOAD_JITTER_MIN;

assets/js/phoenix_live_view/view.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,13 @@ export default class View {
109109
this.ref = 0;
110110
this.lastAckRef = null;
111111
this.childJoins = 0;
112+
/**
113+
* @type {ReturnType<typeof setTimeout> | null}
114+
*/
112115
this.loaderTimer = null;
116+
/**
117+
* @type {ReturnType<typeof setTimeout> | null}
118+
*/
113119
this.disconnectedTimer = null;
114120
this.pendingDiffs = [];
115121
this.pendingForms = new Set();

assets/js/phoenix_live_view/view_hook.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export interface HookInterface {
154154
uploadTo(selectorOrTarget: PhxTarget, name: any, files: any): any;
155155

156156
// allow unknown methods, as people can define them in their hooks
157-
[key: string]: any;
157+
[key: PropertyKey]: any;
158158
}
159159

160160
// based on https://github.com/DefinitelyTyped/DefinitelyTyped/blob/fac1aa75acdddbf4f1a95e98ee2297b54ce4b4c9/types/phoenix_live_view/hooks.d.ts#L26
@@ -204,7 +204,7 @@ export interface Hook<T = object> {
204204
reconnected?: (this: T & HookInterface) => void;
205205

206206
// Allow custom methods with any signature and custom properties
207-
[key: string]: ((this: T & HookInterface, ...args: any[]) => any) | any;
207+
[key: PropertyKey]: any;
208208
}
209209

210210
/**

tsconfig.json

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"target": "es2016",
3+
"target": "es2021",
44
"module": "esnext",
55
"moduleResolution": "node",
66
"allowJs": true,
@@ -12,10 +12,7 @@
1212
"baseUrl": "./assets/js",
1313
"stripInternal": true,
1414
"paths": {
15-
"*": [
16-
"*",
17-
"phoenix_live_view/*"
18-
]
15+
"*": ["*", "phoenix_live_view/*"]
1916
},
2017
"declaration": true,
2118
"emitDeclarationOnly": true,
@@ -24,9 +21,5 @@
2421
"include": [
2522
"./assets/js/phoenix_live_view/*.js",
2623
"./assets/js/phoenix_live_view/*.ts"
27-
],
28-
"exclude": [
29-
"node_modules",
30-
"assets/test/**/*"
3124
]
32-
}
25+
}

0 commit comments

Comments
 (0)