Skip to content

Remove Typescript enums #1337

@mcintyre94

Description

@mcintyre94

We'd probably be better off not using typescript enums, due to them compiling to a slightly complex reverse-mapped function type, and also not being helpful when logged (which we generally try to be with eg our Address type).

We use enums currently for:

export enum Endian {
    Little,
    Big,
}
  • I'd guess that this could just be a union "Little" | "Big"
export enum AccountRole {
    // Bitflag guide: is signer ⌄⌄ is writable
    WRITABLE_SIGNER = /* 3 */ 0b11, // prettier-ignore
    READONLY_SIGNER = /* 2 */ 0b10, // prettier-ignore
    WRITABLE =        /* 1 */ 0b01, // prettier-ignore
    READONLY =        /* 0 */ 0b00, // prettier-ignore
}
  • This would be more useful with string values so that when we log a transaction message instruction account it is legible. We'd need to convert it when compiled though, and would also need to think about the bitshifting used to convert roles etc
export enum OffchainMessageContentFormat {
    RESTRICTED_ASCII_1232_BYTES_MAX = 0,
    UTF8_1232_BYTES_MAX = 1,
    UTF8_65535_BYTES_MAX = 2,
}

This can probably also just a union of strings.

Metadata

Metadata

Assignees

No one assigned

    Labels

    majorThis would require a major version bump

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions