hyperweb-io / hyperweb-io/ts-codegen
[Question] adding undefined for message types
- Lenguaje dominante
- TypeScript
- Estrellas
- 126
- Forks
- 31
- Merge medio
- 19 min
- PR fusionados (30 d)
- 2
Descripción
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.
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Línea de trabajo
Start by tracing the enum parsing and TypeScript type-generation entry points in ts-codegen; the issue does not name specific files or tests. Compare the current Rust enum-to-union output with the requested optional-member shape, then add coverage for Pending, Success, and Error variants so the generated types match the agreed behavior.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- rust, typescript
- Área
- tooling
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100