Skip to content

Commit 64ca1cf

Browse files
committed
fix Tween TS declaration
1 parent 4b1da51 commit 64ca1cf

File tree

1 file changed

+29
-28
lines changed

1 file changed

+29
-28
lines changed

packages/melonjs/src/tweens/tween.ts

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ type OnCompleteCallback<T> = (this: T) => void;
3030
* author lechecacharro<br>
3131
* author Josh Faul / http://jocafa.com/
3232
*/
33-
export default class Tween<T extends Record<string, unknown>> {
34-
_object: T;
33+
export default class Tween {
34+
_object: Object;
3535
_valuesStart: Record<string, unknown>;
3636
_valuesEnd: Record<string, unknown>;
3737
_valuesStartRepeat: Record<string, unknown>;
@@ -43,11 +43,11 @@ export default class Tween<T extends Record<string, unknown>> {
4343
_startTime: number | null;
4444
_easingFunction: EasingFunction;
4545
_interpolationFunction: InterpolationFunction;
46-
_chainedTweens: Tween<Record<string, unknown>>[];
47-
_onStartCallback: OnStartCallback<T> | null;
46+
_chainedTweens: Array<Tween>;
47+
_onStartCallback: OnStartCallback<Object> | null;
4848
_onStartCallbackFired: boolean;
49-
_onUpdateCallback: OnUpdateCallback<T> | null;
50-
_onCompleteCallback: OnCompleteCallback<T> | null;
49+
_onUpdateCallback: OnUpdateCallback<Object> | null;
50+
_onCompleteCallback: OnCompleteCallback<Object> | null;
5151
_tweenTimeTracker: number;
5252
isPersistent: boolean;
5353
updateWhenPaused: boolean;
@@ -68,7 +68,7 @@ export default class Tween<T extends Record<string, unknown>> {
6868
* autoStart : true
6969
* }).onComplete(myFunc);
7070
*/
71-
constructor(object: T) {
71+
constructor(object: Object) {
7272
this.setProperties(object);
7373

7474
this.#boundResumeCallback = this._resumeCallback.bind(this);
@@ -77,14 +77,14 @@ export default class Tween<T extends Record<string, unknown>> {
7777
/**
7878
* @ignore
7979
*/
80-
onResetEvent(object: T) {
80+
onResetEvent(object: Object) {
8181
this.setProperties(object);
8282
}
8383

8484
/**
8585
* @ignore
8686
*/
87-
setProperties(object: T) {
87+
setProperties(object: Object) {
8888
this._object = object;
8989
this._valuesStart = {};
9090
this._valuesEnd = {};
@@ -223,10 +223,14 @@ export default class Tween<T extends Record<string, unknown>> {
223223
}
224224

225225
// create a local copy of the Array with the start value at the front
226-
this._valuesEnd[property] = [this._object[property]].concat(endValue);
226+
this._valuesEnd[property] = [
227+
(this._object as Record<string, unknown>)[property],
228+
].concat(endValue);
227229
}
228230

229-
this._valuesStart[property] = this._object[property];
231+
this._valuesStart[property] = (this._object as Record<string, unknown>)[
232+
property
233+
];
230234

231235
if (!Array.isArray(this._valuesStart[property])) {
232236
(this._valuesStart[property] as number) *= 1.0; // Ensures we're using numbers, not strings
@@ -237,7 +241,6 @@ export default class Tween<T extends Record<string, unknown>> {
237241

238242
return this;
239243
}
240-
241244
/**
242245
* stop the tween
243246
* @returns this instance for object chaining
@@ -304,7 +307,7 @@ export default class Tween<T extends Record<string, unknown>> {
304307
* @param tweens - Tween(s) to be chained
305308
* @returns this instance for object chaining
306309
*/
307-
chain(...tweens: Tween<any>[]) {
310+
chain(...tweens: Tween[]) {
308311
this._chainedTweens = tweens;
309312
return this;
310313
}
@@ -314,7 +317,7 @@ export default class Tween<T extends Record<string, unknown>> {
314317
* @param onStartCallback - callback
315318
* @returns this instance for object chaining
316319
*/
317-
onStart(onStartCallback: OnStartCallback<T>) {
320+
onStart(onStartCallback: OnStartCallback<Object>) {
318321
this._onStartCallback = onStartCallback;
319322
return this;
320323
}
@@ -324,7 +327,7 @@ export default class Tween<T extends Record<string, unknown>> {
324327
* @param onUpdateCallback - callback
325328
* @returns this instance for object chaining
326329
*/
327-
onUpdate(onUpdateCallback: OnUpdateCallback<T>) {
330+
onUpdate(onUpdateCallback: OnUpdateCallback<Object>) {
328331
this._onUpdateCallback = onUpdateCallback;
329332
return this;
330333
}
@@ -334,7 +337,7 @@ export default class Tween<T extends Record<string, unknown>> {
334337
* @param onCompleteCallback - callback
335338
* @returns this instance for object chaining
336339
*/
337-
onComplete(onCompleteCallback: OnCompleteCallback<T>) {
340+
onComplete(onCompleteCallback: OnCompleteCallback<Object>) {
338341
this._onCompleteCallback = onCompleteCallback;
339342
return this;
340343
}
@@ -457,15 +460,13 @@ export default class Tween<T extends Record<string, unknown>> {
457460
}
458461
}
459462

460-
export const tweenPool = createPool(
461-
<T extends Record<string, unknown>>(object: T) => {
462-
const tween = new Tween(object);
463-
464-
return {
465-
instance: tween,
466-
reset(object: T) {
467-
tween.setProperties(object);
468-
},
469-
};
470-
},
471-
);
463+
export const tweenPool = createPool((object: globalThis.Object) => {
464+
const tween = new Tween(object);
465+
466+
return {
467+
instance: tween,
468+
reset(object: globalThis.Object) {
469+
tween.setProperties(object);
470+
},
471+
};
472+
});

0 commit comments

Comments
 (0)