anza-xyz / anza-xyz/kit

Remove Typescript enums

Open
#1,337 1 comment 0 reactions 0 assignees View on GitHub
major
Dominant language
TypeScript
Stars
695
Forks
210
Avg merge
21h 33m
Merged PRs (30d)
90

Description

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:

```ts
export enum Endian {
Little,
Big,
}
```

- I'd guess that this could just be a union `"Little" | "Big"`

```ts
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

```ts
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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.