Skip to content

Commit 9a76656

Browse files
authored
fix: types for setTimeout/setInterval calls (#5726)
1 parent 62b973e commit 9a76656

File tree

9 files changed

+24
-9
lines changed

9 files changed

+24
-9
lines changed

src/background_tokenizer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class BackgroundTokenizer {
2020
* @param {EditSession} [session] The editor session to associate with
2121
**/
2222
constructor(tokenizer, session) {
23-
/**@type {false|number}*/
23+
/**@type {false | ReturnType<typeof setTimeout>}*/
2424
this.running = false;
2525
this.lines = [];
2626
/**@type {string[]|string[][]}*/

src/ext/emmet.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ var editorProxy = new AceEmmetEditor();
324324
exports.commands = new HashHandler();
325325
/**
326326
* @param {Editor} editor
327-
* @return {number|boolean}
327+
* @return {ReturnType<typeof setTimeout> | boolean}
328328
*/
329329
exports.runEmmetCommand = function runEmmetCommand(editor) {
330330
if (this.action == "expand_abbreviation_with_tab") {

src/layer/cursor.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,13 @@ class Cursor {
157157
this.$startCssAnimation();
158158
} else {
159159
var blink = /**@this{Cursor}*/function(){
160+
/**@type{ReturnType<typeof setTimeout>}*/
160161
this.timeoutId = setTimeout(function() {
161162
update(false);
162163
}, 0.6 * this.blinkInterval);
163164
}.bind(this);
164-
165+
166+
/**@type{ReturnType<typeof setInterval>}*/
165167
this.intervalId = setInterval(function() {
166168
update(true);
167169
blink();

src/lib/event.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,12 @@ if (typeof window == "object" && window.postMessage && !useragent.isOldIE) {
322322
}
323323

324324
exports.$idleBlocked = false;
325+
/**
326+
*
327+
* @param {CallableFunction} cb
328+
* @param {number} timeout
329+
* @return {ReturnType<typeof setTimeout>}
330+
*/
325331
exports.onIdle = function(cb, timeout) {
326332
return setTimeout(function handler() {
327333
if (!exports.$idleBlocked) {

src/mouse/mouse_handler.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ class MouseHandler {
117117
this.state = state;
118118
}
119119

120+
/**
121+
*
122+
* @param {MouseEvent} ev
123+
* @param [mouseMoveHandler]
124+
* @return {ReturnType<typeof setTimeout> | undefined}
125+
*/
120126
captureMouse(ev, mouseMoveHandler) {
121127
this.x = ev.x;
122128
this.y = ev.y;

src/tooltip.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ class HoverTooltip extends Tooltip {
193193
constructor(parentNode=document.body) {
194194
super(parentNode);
195195

196+
/**@type{ReturnType<typeof setTimeout> | undefined}*/
196197
this.timeout = undefined;
197198
this.lastT = 0;
198199
this.idleTime = 350;

types/ace-ext.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ declare module "ace-code/src/ext/code_lens" {
252252
}
253253
declare module "ace-code/src/ext/emmet" {
254254
export const commands: HashHandler;
255-
export function runEmmetCommand(editor: Editor): number | boolean;
255+
export function runEmmetCommand(editor: Editor): ReturnType<typeof setTimeout> | boolean;
256256
export function updateCommands(editor: Editor, enabled?: boolean): void;
257257
export function isSupportedMode(mode: any): boolean;
258258
export function isAvailable(editor: Editor, command: string): boolean;

types/ace-lib.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ declare module "ace-code/src/lib/event" {
106106
export function addCommandKeyListener(el: EventTarget, callback: (e: KeyboardEvent, hashId: number, keyCode: number) => void, destroyer?: any): void;
107107
export function nextTick(callback: any, win: any): void;
108108
export const $idleBlocked: boolean;
109-
export function onIdle(cb: any, timeout: any): number;
109+
export function onIdle(cb: CallableFunction, timeout: number): ReturnType<typeof setTimeout>;
110110
export const $idleBlockId: number;
111111
export function blockIdle(delay: any): void;
112112
export const nextFrame: any;

types/ace-modules.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ declare module "ace-code/src/layer/cursor" {
536536
hideCursor(): void;
537537
showCursor(): void;
538538
restartTimer(): void;
539-
intervalId: number;
539+
intervalId: ReturnType<typeof setInterval>;
540540
getPixelPosition(position?: import("ace-code").Ace.Point, onScreen?: boolean): {
541541
left: number;
542542
top: number;
@@ -1625,7 +1625,7 @@ declare module "ace-code/src/mouse/default_handlers" {
16251625
declare module "ace-code/src/tooltip" {
16261626
export class HoverTooltip extends Tooltip {
16271627
constructor(parentNode?: HTMLElement);
1628-
timeout: number;
1628+
timeout: ReturnType<typeof setTimeout> | undefined;
16291629
lastT: number;
16301630
idleTime: number;
16311631
lastEvent: import("ace-code/src/mouse/mouse_event").MouseEvent;
@@ -1740,7 +1740,7 @@ declare module "ace-code/src/mouse/mouse_handler" {
17401740
}): void;
17411741
setState(state: any): void;
17421742
state: any;
1743-
captureMouse(ev: any, mouseMoveHandler: any): number;
1743+
captureMouse(ev: MouseEvent, mouseMoveHandler?: any): ReturnType<typeof setTimeout> | undefined;
17441744
x: any;
17451745
y: any;
17461746
isMousePressed: boolean;
@@ -3582,7 +3582,7 @@ declare module "ace-code/src/background_tokenizer" {
35823582
* @param {EditSession} [session] The editor session to associate with
35833583
**/
35843584
constructor(tokenizer: Tokenizer, session?: EditSession);
3585-
running: false | number;
3585+
running: false | ReturnType<typeof setTimeout>;
35863586
lines: any[];
35873587
states: string[] | string[][];
35883588
currentLine: number;

0 commit comments

Comments
 (0)