Dumb question about Colyseus typescript syntax

16 Apr 2020, 21:42

I'm a TS newbie. I see Colyseus example code like

@type("number")
x = 4;

I can't find other examples of this syntax in typescript documentation. What is it? It looks more like type annotations that normally appear in code comments.

Why doesn't it use the typescript colon syntax, as in

x:number = 4;

16 Apr 2020, 21:58

Hi @tsum, welcome!

That's called a decorator. It is used to expose types to the runtime serializer. Regular TypeScript types are only available during compile time.

Cheers

16 Apr 2020, 22:06

@endel Thank you!