LoginSignup
0

More than 3 years have passed since last update.

Firebase Typescript エラー対応

Posted at

どうもFirebase Typescriptのバージョンが上がったかコンパイルのルールが厳しくなったかでエラーが出ているので修正した例をあげておきます。

型がないとダメ?

メソッド引数

修正前

Parameter 'object' implicitly has an 'any' type.

    function objectSort(object) {

修正後

    function objectSort(object: any) {

修正前

Parameter 'fcmToken' implicitly has an 'any' type.

    const pushMessageChat = (fcmToken, nickname, badge) => ({

修正後

    const pushMessageChat = (fcmToken :any, nickname :any, badge :any) => ({
ハッシュ、配列

修正前

Variable 'array' implicitly has type 'any[]' in some locations where its type cannot be determined.

     var array = [];

修正後

     var array :any = [];

修正前

Variable 'array' implicitly has type 'orders ' in some locations where its type cannot be determined.

     const orders = []

修正後

     const orders :any = [];

forn文がそのままでは使えない?

for

修正前

 Cannot assign to 'i' because it is a constant.

     for (const i = 0; i < array.length; i++) {

修正後

    const i;
    for (i = 0; i < array.length; i++) {

オブジェクトのチェックが必要?

for

修正前

Object is possibly 'undefined'.

    const newValue = snap.data()
    const newHistory = newValue.history

修正後

    const newValue = snap.data()
    if ( newValue === undefined) return

    const newHistory = newValue.history

修正してやっとPush通知が送れるようになった・・・

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0