We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
該当箇所 → https://github.com/traPtitech/traQ_S-UI/blob/master/src/components/Modal/ModalContainer.vue#L70-L98
オブジェクトを使って分岐する
例えばcomponentType = 'a' | 'b' | 'c'という型のtypeに対してcomponentA、componentB、componentCをそれぞれ返したいときは、次のように書くことで型安全に書くことができる。
componentType = 'a' | 'b' | 'c'
type
componentA
componentB
componentC
const componentMap: Record<componentType, ComponentPublicInstance> = { a: componentA, b: componentB, c: componentC, }; return componentMap[type];
この例において、componentType = 'a' | 'b' | 'c' | 'd'となったときはプロパティdに対応するコンポーネントが存在しないため型チェックでエラーを吐いて無事修正を見落とすことがなくなる。
componentType = 'a' | 'b' | 'c' | 'd'
d
The text was updated successfully, but these errors were encountered:
No branches or pull requests
該当箇所 → https://github.com/traPtitech/traQ_S-UI/blob/master/src/components/Modal/ModalContainer.vue#L70-L98
現時点の書き方の問題
新しい書き方
オブジェクトを使って分岐する
例えば
componentType = 'a' | 'b' | 'c'
という型のtype
に対してcomponentA
、componentB
、componentC
をそれぞれ返したいときは、次のように書くことで型安全に書くことができる。この例において、
componentType = 'a' | 'b' | 'c' | 'd'
となったときはプロパティd
に対応するコンポーネントが存在しないため型チェックでエラーを吐いて無事修正を見落とすことがなくなる。The text was updated successfully, but these errors were encountered: