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

vladimir-tikhonov picture vladimir-tikhonov  ·  4Comments

drachehavoc picture drachehavoc  ·  6Comments

DuncanUszkay1 picture DuncanUszkay1  ·  3Comments

torch2424 picture torch2424  ·  5Comments

evgenykuzyakov picture evgenykuzyakov  ·  3Comments