Skip to content

RawRepresentable対応#42

Merged
omochi merged 1 commit intomainfrom
rawrepresentable
Dec 2, 2022
Merged

RawRepresentable対応#42
omochi merged 1 commit intomainfrom
rawrepresentable

Conversation

@omochi
Copy link
Owner

@omochi omochi commented Dec 2, 2022

#40 の対応

Swift側の型情報をなるべくTypeScriptで再現するため、phantom typeの生成を導入した。

// 入力ソース
struct ID {
  var rawValue: String
}
// 生成コード
type ID = string & { ID: never };

判定は rawValue プロパティを見ているだけのガバガバ実装。

@omochi omochi merged commit 1403f16 into main Dec 2, 2022
@omochi omochi deleted the rawrepresentable branch December 2, 2022 11:36
S: never;
};
""", """
export type S_JSON = E_JSON & {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここは変に感じました。
JSON型は実際にSwiftとTS間でやりとりされるjsonの構造を忠実に表したものだと思っていて、そこにはarray, object, null, number, stringのようなjsonの基本型以外のものは現れないと思いました。
型付けはEntity型に変化する際に行われる(enumはそう)ので、Phantom Typeの型付けもEntity型への変換タイミングで行うべきに思いました。

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

あ〜なるほど。その方が正しいですね。直します。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants