【发布时间】:2018-08-17 18:09:48
【问题描述】:
这个问题与 TypeScript 密切相关。如果我在 Cocos Creator 中有基于 JavaScript 的 Cocos 项目,我遇到的问题可以完美运行。
我在名为 enums 的文件中有以下枚举。
export const enum CollisionType {
Static= 0,
Dynamic= 1,
Solid= 2,
SemiSolid= 3
}
在我的 game.ts 文件中,我有以下内容
import {CollisionType} from "./Enums";
export default class PlayerControl extends cc.Component {
@property (CollisionType)
collisionType:CollisionType = CollisionType.Static;
但不幸的是,这不起作用。我在 CollisionType 下得到一条红线并出现以下错误:
Argument of type 'typeof CollisionType' is not assignable to parameter of type 'string | number | boolean | Function | any[] | { type?: any; visible?: boolean | (() => boolean); displayName?: string; tooltip?: string; multiline?: boolean; readonly?: boolean; min?: number; max?: number; ... 7 more ...; animatable?: boolean; } | ValueType'.
如果我不将@property 设置为我的变量,它可以正常工作,但是无法在 Cocos Creator 编辑器中编辑此值。
有什么想法吗?
【问题讨论】: