1.5.0-beta2 typescript @propery bug

  1. 分别使用ts和js对字符串属性text封装get set 方法,代码如下

test.ts

const {ccclass, property} = cc._decorator;

@ccclass
class NewClTetass extends cc.Component {
    @property({
        default: "hello",
    })
    public hideText: string = "hello";

    @property({
        get: () => {return this.hideText},
        set: (value : string) => { this.hideText = value; }
    })
    public text: string = "hello";
    

    public onLoad() {

    }
}

test-in-js.js

cc.Class({
    extends: cc.Component,

    properties: {
        hideText:"hello",
        text:{
            get:function(){
                return this.hideText;
            },
            set:function(value){
                this.hideText = value;
            }
        }
    },

    onLoad: function () {

    },

});

回到编辑器,将test.ts和test-in-js.js挂载到canvas节点,效果如图

此时,分别修改test.js和test-in-js.js的text属性为hello again,效果如图

test-in-js能够正常地同步至hideText。
而test.ts并不能同步至hideText。

另外在test.ts中 将hideText修改为_hideText,哪怕hideText的访问权限是public 在编辑器中也不会显示这个属性,我有点怀疑人生。。这个public形同虚设。。

@Jare老师 您的40寸液晶超清大锅已经到楼下了,麻烦取一下快递233。

哈哈哈哈哈哈哈,40寸液晶3D超清4K大锅

这个测试可用:

const {ccclass, property} = cc._decorator;

@ccclass
class NewClTetass extends cc.Component {
    @property({
        default: "hello"
    })
    public hideText: string = "hello";

    @property({
        default: "hello"
    })
    public text: string = "hello";
    public get text() {
        return this.hideText;
    }

    public set text(value) {
        this.hideText = value;
    }

    public onLoad() {

    }
}

这个你自己已经划掉了,我还是再澄清下,ts 中的 public 用不到,这个只是给 IDE 用的,编辑器无法获取。(也没有任何文档说过 Creator 中的 public 会影响 visible)

这里的写法有问题,get/set 不应该写在 property 中,而是应该用 ts 的标准写法声明 getset。应该是有报错的,晚点我确认下是不是报错没打印出来

反弹!!!!!

:joy:容我静悄悄地把锅背走

这里确实没报错,下个版本会有详细的报错信息,这样你们就知道要怎么写才对了。

这么大锅背来背去,累不累?:relieved:

楼主怎么配置creator 1.4.2以上版本的TypeScript版的,求指点