'TypeScript- TypeError: "SampleClass.sampleFunction" is not a function

I'm using Cocos Creator and TypeScript to develop my web based 2D game. I faced the following error while calling onTapFalse function.

Uncaught TypeError: playableObj.onTapFalse is not a function

here's onTapFalse function:

@ccclass('PlayableObject')
export class PlayableObject extends Component {
    public onTapFalse() {
        // ...
    }
}

I call onTapFalse here:

@ccclass('CorrectionHandler')
export class CorrectionHandler extends Singleton<CorrectionHandler> {
    public correct(playableObj: PlayableObject){
        if (!playableObj.isTrue)playableObj.onTapFalse();
    }
}

What's the solution?

thanks



Solution 1:[1]

I found out I passed a parameter of wrong type (a type other than PlayableObject) to the correct function. So playableObject.isTrue was always false because of there isn't the isTrue in this class, also there isn't the onTapFalse function.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Abolfazl