Assemblyscript: Support string enums

Created on 26 Mar 2019  路  4Comments  路  Source: AssemblyScript/assemblyscript

enum Weekend {
  Friday = 'FRIDAY',
  Saturday = 'SATURDAY',
  Sunday = 'SUNDAY'
}
enhancement

All 4 comments

I'm interested in working on this feature. Any guidance as to what would be a good place to start?

Also, do we want to support something like this -

enum BooleanLikeHeterogeneousEnum {
    No = 0,
    Yes = 'YES',
}

Also, do we want to support something like this

I think yes. Actually enum is just another variant of grouped constants under same namespace, so BooleanLikeHeterogeneousEnum.No should just replace to 0 and BooleanLikeHeterogeneousEnum.YES to 'YES'.

@dcodeIO wdyt?

Type-wise the compiler currently assumes that var a: SomeEnum is i32. As such, mixing different kinds of values appears problematic in about the same way union types are. Pure string enums should be possible in the same way

namespace Weekend {
  const Friday = 'FRIDAY';
  const Saturday = 'SATURDAY';
  const Sunday = 'SUNDAY';
}
type Weekend = string;

is. How important would you say string enums are over this syntax?

Removing the good first issue label here, because this might become quite tricky. Not super tricky, but potentially too tricky for a very first issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

blooddy picture blooddy  路  3Comments

jarble picture jarble  路  3Comments

jerrywdlee picture jerrywdlee  路  4Comments

DuncanUszkay1 picture DuncanUszkay1  路  3Comments

vladimir-tikhonov picture vladimir-tikhonov  路  4Comments