空のenumのトランスパイル先としてneverではなくvoidを選べるようにする #130
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
従来、空のenumはneverにトランスパイルしていた。
しかしこれには型タグが付いていないという問題があり、
以下のようなSwiftコードで問題があった。
一見、neverに型タグを付ければ良さそうだが、
ここでTypeScriptコンパイラが特殊な挙動をしてしまい、
仮に以下のようにコード生成しても
FooIDのタグは期待されるとはならず
となってしまう。
これではタグ型がタグとして機能しないので困る。
そこでこのパッチでは、代わりに
とトランスパイルするモードを追加する。
これだと期待通りタグが機能する。
従来の never への変換は、
それはそれで型の値が存在しないことを意味する点で望ましいため、
仕様変更をせずにデフォルトの挙動として維持する。
新しいvoidへの変換は
EnumConverterに指定するAPIオプションとして提供する。ユーザーはこれを custom type converter を使用して、
特定の enum 型の変換の挙動として指定することができる。
またこの際、
全ての enum 型についての挙動を変更することもできるように、
デフォルトの type converter 選択を直接再利用できるようにAPI化した。
テストケースではそのようなセットアップをした。