anza-xyz / anza-xyz/kit

Remove Typescript enums

未關閉
#1,337 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
major
主要語言
TypeScript
星號
695
分支
210
平均合併
21 小時 33 分鐘
30 天內合併 PR
90

描述

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.

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。