Warm tip: This article is reproduced from serverfault.com, please click

Are there Enums in Neo-One Smart Contracts?

发布于 2020-11-21 17:01:15

Is there a possibility to use enums in neo-one smart contracts? I tried to declare an enum, but got the following error:

error

This is how I declared it:

enum testEnum{
  a,
  b,
  c,
}

export class Token extends SmartContract {
  private t: testEnum = testEnum.a;
}

It seems that not all typescript types are supported, or I declared it wrong.

Questioner
max123
Viewed
0
Spencer 2020-11-28 15:43:51

The NEO•ONE TypeScript Smart Contract compiler actually does not currently support enums, which is why you are getting that error. When the compiler runs into an enum declaration (via the enum keyword) it just reports an unsupported syntax error. So I recommend just using a plain JS "object" to accomplish the same thing. Like this:

const testEnum = {
   a: 'a',
   b: 'b',
   c: 'c',
};