1

I am writing a simple app in ionic 2 but I have a problem with the anc (Angular compiler) because when I run ionic serve it gives me the warning but the app runs on the browser normally, but when I try to build for my phone it breaks and the build process results an error.

  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));
      }
    });

The Line that triggers the error is : var allResponses: Array = >JSON.parse(data);

And the error is :

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

And I am getting a type error in the compiler and I am starting to think that this might be a bug after all.

1
  • .then((data: string) => { maybe might work Commented Oct 6, 2016 at 13:10

1 Answer 1

1

According to the documentation, json.parse() expects a string as input, I believe your data parameter is an object.

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

Sign up to request clarification or add additional context in comments.

1 Comment

Yes you are actually right :/ the thing is that it was running normally on the browser and parsing correctly. Thank you for the very very fast response!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.