hyperweb-io / hyperweb-io/ts-codegen

[Question] adding undefined for message types

オープン
#88 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
TypeScript
スター
126
フォーク
31
平均マージ
19分
マージ済み PR(30日)
2

説明

I have an enum:
```rs
pub enum MintStatus {
Pending{},
Success{token_id: String},
Error{message: String},
}
```

This enum is a response to a query in my contract, when I use ts-codegen, it parses it to this:
```ts
export type MintStatus = {
pending: {};
} | {
success: {
token_id: string;
};
} | {
error: {
message: string;
};
};
```

To me it feels wrong, because this forces me to cast my `MintStatus` type into `any`, in order to do something like this:
```ts
let mintStatus = query() as any;
if(mintStatus.success) {
let tokenId = mintStatus.success.token_id;
}
```

I would suggest to change the parsing into something like this:
```ts
export type MintStatus = {
pending: {} | undefined;
success: {
token_id: string;
} | undefined;
error: {
message: string;
} | undefined;
};
```

This change will allow me to avoid the `any` cast, and allow me to get TS work correctly for this type.
Right now it doesn't give me any auto completion and complains when I do not cast to any.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

まず、ts-codegen における enum の解析と TypeScript 型生成のエントリーポイントを追跡してください。この issue では具体的なファイルやテストは指定されていません。現在の Rust の enum から union への出力を、要求されているオプショナルメンバーの形と比較し、その後 Pending、Success、Error の各 variant に対するカバレッジを追加して、生成される型が合意された動作と一致するようにしてください。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
rust, typescript
領域
tooling
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。