Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EngineIdをユニークな型にする #1172

Merged

Conversation

Hiroshiba
Copy link
Member

内容

EngineIdをただのstringからユニークな型(brand型)に変更します。
これによりRecordのキーなどの変数が厳密になり、コーディングミスを失くしやすくなるはず・・・!

関連 Issue

その他

方針としては、string型になっていたところを全てEngineIdにしています。
またzod schemaが必要なとろろはengineIdSchemaを指定しています。

一部undefinableにする必要があり、throw Errorするロジック周りがたされていたりします。

@Hiroshiba Hiroshiba requested a review from a team as a code owner February 2, 2023 18:52
@Hiroshiba Hiroshiba requested review from y-chan and removed request for a team February 2, 2023 18:52
Comment on lines +7 to +9
export const engineIdSchema = z.string().uuid().brand<"EngineId">();
export type EngineId = z.infer<typeof engineIdSchema>;
export const EngineId = (id: string): EngineId => engineIdSchema.parse(id);
Copy link
Member Author

@Hiroshiba Hiroshiba Feb 2, 2023

Choose a reason for hiding this comment

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

ここがEngineIdを型定義している場所です。

@Hiroshiba
Copy link
Member Author

Hiroshiba commented Feb 2, 2023

型周りに強い @Segu-g さん・ @yamachu さん、あと全体的に詳しい @y-chan さん辺りにレビュー頂けるととても心強いです 🙇‍♂️
(影響範囲が広いため、期間が長くなれば長くなるほど苦しくなってくる系なので、何卒・・・・・・・・!!!! 🙇 🙇 🙇 )

@Hiroshiba
Copy link
Member Author

が入ったあとに修正してマージが良さそう?

@Hiroshiba
Copy link
Member Author

#1092 が入ったmainをマージしました・・・!

Copy link
Contributor

@yamachu yamachu left a comment

Choose a reason for hiding this comment

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

とりあえず気になった個所としてはこんなものかなぁと
Mapの箇所はおいおい変えたいなぁと思う程度で今回変更は不要かなと思いますが、characterInfos辺りが意図通りなのかが気になりました

src/background.ts Outdated Show resolved Hide resolved
src/background/engineManager.ts Show resolved Hide resolved
src/components/EngineManageDialog.vue Show resolved Hide resolved
src/store/setting.ts Show resolved Hide resolved
@@ -88,16 +89,19 @@ const engineInfos = computed(
() =>
new Map(
Object.entries(store.state.characterInfos).map(
Copy link
Contributor

Choose a reason for hiding this comment

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

型見る感じ単純なstringとして扱ってそうに見えたけれども、ここの変更は意図通りですか?
あと実際に動かしていないのですが、symbolを付けたstring(すなわちEngineIdですが)を再度EngineIdコンストラクタみたいなのを通すとどうなるんですか?(って質問しようとしてコード見たらzodでstringとして扱ってみたいな感じだったから、単純なtoString()が呼ばれて再度symbol付け直す感じなのかな…

Copy link
Member Author

Choose a reason for hiding this comment

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

単純なstringとして扱ってそう

これってどこのことでしょうか 👀
engineIdStrであればEngineIdでラップしてるはず・・・?

再度EngineIdコンストラクタみたいなのを通すと

試してみた感じ同じ型になってそうでした!!
image

Copy link
Contributor

Choose a reason for hiding this comment

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

https://github.com/VOICEVOX/voicevox/pull/1172/files#diff-0493b4f4568a8a79680f5058a82555a336c9956bb1b8599960410e8d8f23c15eR114

characterInfosのkeyがstringとして扱われてるのですよね
EngineIdがkeyなのであれば、これは型として表現した方がいいなと思ったのでした(ということで、types.tsの方の変更requestです)
コメントを付けた箇所は、よくわからないstringをEngineIdとして扱っているわけではなさそうなので、ここに関しては変更不要です(Object.entriesの弊害がまた出てしまったみたいな顔をしながら

Copy link
Member Author

Choose a reason for hiding this comment

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

あ、なるほどです!ほんとですね!!
stringに代入できてしまうんですね・・・。
EngineIdになってなかったRecordがいくつかあったので一緒に直してみました!!

@Hiroshiba
Copy link
Member Author

レビューありがとうございます!!!

Copy link
Member Author

@Hiroshiba Hiroshiba left a comment

Choose a reason for hiding this comment

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

大丈夫だと思うのでマージします!!
(大丈夫じゃなくても致命的なエラーにはならないはず)

@Hiroshiba Hiroshiba merged commit b6a0d11 into VOICEVOX:main Feb 9, 2023
@Hiroshiba Hiroshiba deleted the engineIdにユニークな型をつける branch February 9, 2023 15:46
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