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

262 Views Asked by At

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

1

There are 1 best solutions below

0
Abolfazl On

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.