acacode / acacode/swagger-typescript-api

Non generic syntax for generating types with discriminators

オープン
#677 コメント 0 件 リアクション 1 件 担当者 0 名 GitHub で見る
主要言語
TypeScript
スター
4.1k
フォーク
436
PR マージ指標
30日以内にマージされた PR はありません

説明

I am generating zod schemas based on types generated by swagger-typescript-api. The schema generation doesn't work well with generics so I was wondering if it would be possible to have an alternative way of generating types with discriminators?

Today, this is the syntax it seems:
```
export type Value = BaseValue &
(
| BaseValueTypeMapping<"Type1", Value1>
| BaseValueTypeMapping<"Type2", Value2>
| BaseValueTypeMapping<"Type3", Value3>;

export type Value1 = BaseValue;

export type Value2 = BaseValue ;

export type Value3 = BaseValue ;

interface BaseValue {
$type: string;
value: number;
}

type BaseValueTypeMapping = {
$type: Key;
} & Type;
```

It would be nice if it was possible to just generate the types with discriminators like so:

```
export type Value = BaseValue &
(
| Value1
| Value2
| Value3 ;

export type Value1 = BaseValue & {
$type: "Type1"
};

export type Value2 = BaseValue & {
$type: "Type2"
};

export type Value3 = BaseValue & {
$type: "Type3"
};

interface BaseValue {
$type: string;
value: number;
}
```

Is this possible?

Thanks

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

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

評価

この issue はまだ評価されていません。

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

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