I’m a bit confused about using get/set on components written with TypeScript. Let me show you an example:
@ccclass
export default class BugExample extends cc.Component {
@property(cc.Label)
_label:cc.Label = null;
@property(cc.Label)
get label():cc.Label
{
return this._label;
}
set label(value:cc.Label)
{
this._label = value;
}
}
As you can see I have hidden property _label
and then a getter and setter label
.
This produces such error in CocosCreator:
The 'default' value of 'BugExample.label' should not be used with a 'get' function.
Some of the outdated documentation shows usage of a default
in full property
object, however in Cocos 1.9 compiler throws error here, that default
property is not allowed. The same with writing get/set
methods inside a property
, which was also suggested not to do in type script in some similar post from Cocos 1.5.
Anyway, I couldn’t get rid of this error. What is the most interesting here, that I finally got rid of it accidentaly. If you simply change this line:
@property(cc.Label)
into this:
@property({
type:cc.Label
})
the errors are gone, even though both versions are doing exactly the same, the first one is just shorter.
Could anyone answer me, if it’s a bug or not, and what is proper way to make such functions?