Version
- Phaser Version: N/A (Occurs on master)
- Operating system: N/A
- Browser: N/A
Description
The type for callbacks is incorrect - instead of a partial object that might have each callback, it's an object that ALWAYS has every single callback (though each may be set to null).
|
this.callbacks = { |
|
onActive: null, |
|
onComplete: null, |
|
onLoop: null, |
|
onPause: null, |
|
onRepeat: null, |
|
onResume: null, |
|
onStart: null, |
|
onStop: null, |
|
onUpdate: null, |
|
onYoyo: null |
|
}; |
MOREOVER, the data added by setCallback is NOT a simple lambda function! It's an object containing the extra parameters!
|
if (this.callbacks.hasOwnProperty(type)) |
|
{ |
|
this.callbacks[type] = { func: callback, params: params }; |
|
} |
This is BLATANTLY type-unsafe due to effectively misrepresenting the type's very nature - the declaration file says "record of lambda functions", the code says "record of objects with lambda functions".
Current (incorrect) typing
type TweenCallbacks = {
/**
* A function to call when the tween becomes active within the Tween Manager.
*/
onActive?: Phaser.Types.Tweens.TweenOnActiveCallback;
/**
* A function to call when the tween starts playback, after any delays have expired.
*/
onStart?: Phaser.Types.Tweens.TweenOnStartCallback;
/**
* A function to call when the tween completes.
*/
onComplete?: Phaser.Types.Tweens.TweenOnCompleteCallback;
/**
* A function to call each time the tween loops.
*/
onLoop?: Phaser.Types.Tweens.TweenOnLoopCallback;
/**
* A function to call each time the tween is paused.
*/
onPause?: Phaser.Types.Tweens.TweenOnPauseCallback;
/**
* A function to call each time the tween is resumed.
*/
onResume?: Phaser.Types.Tweens.TweenOnResumeCallback;
/**
* A function to call each time the tween repeats. Called once per property per target.
*/
onRepeat?: Phaser.Types.Tweens.TweenOnRepeatCallback;
/**
* A function to call when the tween is stopped.
*/
onStop?: Phaser.Types.Tweens.TweenOnStopCallback;
/**
* A function to call each time the tween steps. Called once per property per target.
*/
onUpdate?: Phaser.Types.Tweens.TweenOnUpdateCallback;
/**
* A function to call each time the tween yoyos. Called once per property per target.
*/
onYoyo?: Phaser.Types.Tweens.TweenOnYoyoCallback;
};
Example Test Code
const tween = scene.tweens.add({targets: sprite, duration: 400, on});
if (tween.callbacks.onComplete === null) {} // TS says impossible, but actually runs
tween.callbacks.onComplete?.() // CRASHES because it's not a function!
Additional Information
The callbacks themselves should also probably be readonly, given the setCallback function's entire purpose is to modify them.
Version
Description
The type for
callbacksis incorrect - instead of a partial object that might have each callback, it's an object that ALWAYS has every single callback (though each may be set tonull).phaser/src/tweens/tween/BaseTween.js
Lines 220 to 231 in 41be1e4
MOREOVER, the data added by
setCallbackis NOT a simple lambda function! It's an object containing the extra parameters!phaser/src/tweens/tween/BaseTween.js
Lines 621 to 624 in 41be1e4
This is BLATANTLY type-unsafe due to effectively misrepresenting the type's very nature - the declaration file says "record of lambda functions", the code says "record of objects with lambda functions".
Current (incorrect) typing
Example Test Code
Additional Information
The callbacks themselves should also probably be readonly, given the
setCallbackfunction's entire purpose is to modify them.