TypeScript property

creator 版本: 2.2.0

创建typeScript脚本

声明代码: @property({default:'abc', multiline:true, notify: function () { //我的操作; }}) abc;

这个时候会报错,default不在类型中

看了下,default, notify都不在creator.d.ts的property中

typescript没有notify,notify只是在javascript中使用,typescript中建议用setter/getter来使属性在设置时进行一些其他的调用。
另外你这个格式也不对吧
正常应该是

    private _text: string = 'abc';

    @property({multiline: true})
    set text (value: string) {
        this._text = value;
        //do something
        this.doSomething();
    }
    get text (): string {
        return this._text;
    }

多谢指教:heart_eyes:

_text也要加@property不然不会保存,text是没有实体的

@property
private _text: string = 'abc';

@property({multiline: true})
set text (value: string) {
    this._text = value;
    //do something
    this.doSomething();
}
get text (): string {
    return this._text;
}
1赞

js的话,我也是用get set,notify有bug,不能在编辑器及时更新

就是 咋解决的啊

https://forum.cocos.org/t/typescript-property/86495/4?u=kingcoc


这个就是解决方案

_text 前面有下划线,不会暴漏给编辑器
编辑器显示的是 text