不多说,直接贴出错的代码
//b.ts 即将要被导入的文件
const {ccclass, property} = cc._decorator;
@ccclass
export default class GameStateMgr extends cc.Component {
public text: string = ‘hello’;
}
注:这里还试过下面这种写法,得到一样的报错。
@property(cc.String)
text: string = ‘hello’;
//a.ts
const {ccclass, property} = cc._decorator;
import GameState from ‘./gameStateMgr’;
@ccclass
export default class Game extends cc.Component {
onLoad () {
var aaa = GameState.text;
console.log(aaa);
}
}
在编辑器里text直接提示错误,Property ‘text’ does not exist on type ‘typeof GameStateMgr’,如果硬是要编译,打印出来的是undefined
看了些类似问题,好像都是直接声明一下就能用了,我这个怎么就不行呢?
- Creator 版本:2.4.3