What is the correct way to type events?

What is the correct way to type events?
0.0 0


I get an error in VSCode when doing it like the docs describe it.

42 PM



This is how I handle touch events in my game. I always attach them to a node:

this.node.on(cc.Node.EventType.TOUCH_START, this.touchStart, this);
this.node.on(cc.Node.EventType.TOUCH_MOVE, this.touchMove, this);
this.node.on(cc.Node.EventType.TOUCH_END, this.touchEnd, this);
this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.touchCancel, this);

Use the functions tuchStart(event), touchMove(event), touchEnd(event) and touchCancel(event) to handle your touch events.


Yes, and it works but VSCode doesn’t seem to know about EventType.


I’m not having this issue. At least its is not happening with 1.5.2.
Do you work with TS? Maybe the issue is in the d.ts file… Still, works great on my computer and no warnings/unknown syntax. But I believe I’m not using the d.ts that comes with version 1.5.2… I think do have the one that comes with version 1.6 or 1.7.


Yep, I have had the latest d.ts file installed for all versions up until the current 1.7b7. All of them have complained about EventType.

It’s not a game breaker - I’d just like to remove as many red markings as possible.


Ok, I got it figured out by using cc.Event.EventTouch and cc.Event.EventMouse.

No more errors in VS Code