2016-10-06 11 views
1

イオン2の単純なアプリケーションを作成していますが、イオンサーブを実行すると警告メッセージが表示されますが、アプリケーションは実行されるため、anc(角度コンパイラ)に問題があります。ブラウザは正常に動作しますが、電話機のためにビルドしようとすると、ビルドプロセスがエラーとなり、ビルドが中断されます。Typescript角型2 /イオン2のキャストエラー

var tempResults: ResultModel = new ResultModel(currentOne.id, (me.res.length > 1) ? me.res[0] : me.res[0], (me.res.length > 1) ? me.res[1] : me.res[0], currentOne.question, currentOne.imagePath); 
    console.log(localforage.hasOwnProperty('result')) 
    localforage.getItem('results').then(data=> { 
     var allResponses: Array<ResultModel> = new Array<ResultModel>(); 
     if (data != null) { 

     var allResponses: Array<ResultModel> = <Array<ResultModel>>JSON.parse(data); 
      allResponses.push(tempResults); 
     localforage.setItem('results', JSON.stringify(allResponses)); 
     } else { 
     allResponses.push(tempResults); 
     localforage.setItem('results', JSON.stringify(allResponses)); 
     } 
    }); 

エラーをトリガするラインである: VARのallResponses:配列=> JSON.parse(データ)。

とエラーは次のようになります。

ngc error: Error: Error at C:/Users/.../result-item.ts:23:52: Argument of type '{}' is not assignable to parameter of type 'string'.

そして、私は、コンパイラで型エラーを取得していますし、私は、これは結局バグかもしれないと考え始めています。

+0

'.then((データ:文字列)=> {'多分 –

答えて

1

ドキュメントによると、json.parse()は文字列を入力とみなしていますが、データパラメータはオブジェクトだと思います。

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse

+0

はい、あなたが実際に正しい動作する可能性があります。の事は、それがブラウザ上で正常に実行されていると正しく解析したことがある/いただきありがとうございます非常に速い応答!! –

関連する問題