tukumo-n9 / horse-racing-betting-ticket-manager

競馬で購入した馬券の収支を管理するWebアプリ
https://horse-racing-ticket-manager.web.app/
0 stars 0 forks source link

Firebaseでホスティングする #11

Closed tukumo-n9 closed 1 month ago

tukumo-n9 commented 4 months ago
tukumo-n9 commented 3 months ago

buildコマンドでエラーが出た EditTicketFormコンポーネントで出ている型定義エラーが原因? 編集する際に読み込んでいる馬券の情報がundefinedになる可能性を示している URLから存在しない馬券の詳細・編集ページにアクセスできる React Routerで存在しないURLにアクセスした場合は404ページにする 馬券データが見つからない場合、早期リターンする

tukumo-n9 commented 3 months ago

とりあえず、ホスティングができるようにする

存在しない馬券データにアクセスした際のリダイレクト処理や、細かい型定義は後回しにする

tukumo-n9 commented 3 months ago

馬券データがundefinedの可能性があるとのTSエラーは、ticketの条件付きレンダーとticketオブジェクトの非nullアサーションで突破できた。 弊害や落とし穴について今後把握しておきたい。 あとは、No overload matches this call… の解決のみ。

tukumo-n9 commented 3 months ago

該当箇所

await updateDoc(doc(db, "users", user.uid, "tickets", ticketId), {

出ているエラー

No overload matches this call.
  Overload 1 of 3, '(firestore: Firestore, path: string, ...pathSegments: string[]): DocumentReference<DocumentData, DocumentData>', gave the following error.
    Argument of type 'string | undefined' is not assignable to parameter of type 'string'.
      Type 'undefined' is not assignable to type 'string'.
  Overload 2 of 3, '(reference: CollectionReference<unknown, DocumentData>, path?: string | undefined, ...pathSegments: string[]): DocumentReference<unknown, DocumentData>', gave the following error.
    Argument of type 'Firestore' is not assignable to parameter of type 'CollectionReference<unknown, DocumentData>'.
      Type 'Firestore' is missing the following properties from type 'CollectionReference<unknown, DocumentData>': id, path, parent, withConverter, and 2 more.
  Overload 3 of 3, '(reference: DocumentReference<unknown, DocumentData>, path: string, ...pathSegments: string[]): DocumentReference<DocumentData, DocumentData>', gave the following error.
    Argument of type 'Firestore' is not assignable to parameter of type 'DocumentReference<unknown, DocumentData>'.
      Type 'Firestore' is missing the following properties from type 'DocumentReference<unknown, DocumentData>': converter, firestore, id, path, and 2 more.

原因

TSのオーバーロード関数の型定義がうまくいっていない? Firestoreのdoc関数には型定義をしていないので、勝手につくやつなのか。 doc関数に複数の型シグネチャがあるようなので、それぞれ返り値の型か引数の型がおかしいのか見ていく。

疑問

エラーの2行目は関数の型定義なのか?

tukumo-n9 commented 2 months ago

Firestoreを方安全に使う方法についての記事があった これを読みつつ試していく https://zenn.dev/arark/articles/9ef42ee801050e0f9b88

tukumo-n9 commented 2 months ago

doc関数の引数に非nullアサーション演算子をつけたら一旦エラーはなくなった 必ずnullかundefinedではないとプログラマー側から主張するということだが、全然例外がありそうなので弊害についてもおいおい調べていく とりあえずは解決か

await updateDoc(
  doc(db!, "users"!, user!.uid!, "tickets"!, ticketId!),
  {
tukumo-n9 commented 2 months ago

Todo

React Router + Firebase Authenticationのルーティングについて実例を調べる