question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feedback]Tons of errors in Angular 12 app

See original GitHub issue

Page: /start/getting-started/data-model/q/integration/angular

Feedback:

Here are the following errors I am seeing initially, I attempted to fix some.

  1. Need to move the code from onInit into the constructor.
  2. Rrename file, ‘aws-exports.js’ to ‘aws-exports.ts’
  3. Assign empty array to class field restaurants: Array<Restaurant> = [];
Error: src/app/app.component.ts:13:10 - error TS2564: Property 'createForm' has no initializer and is not definitely assigned in the constructor.

13   public createForm: FormGroup;
            ~~~~~~~~~~


Error: src/app/app.component.ts:15:3 - error TS2564: Property 'restaurants' has no initializer and is not definitely assigned in the constructor.

15   restaurants: Array<Restaurant>;
     ~~~~~~~~~~~


Error: src/app/app.component.ts:16:3 - error TS7008: Member 'subscription' implicitly has an 'any' type.

16   subscription;
     ~~~~~~~~~~~~


Error: src/app/app.component.ts:29:7 - error TS2322: Type '({ __typename: "Restaurant"; id: string; name: string; description: string; city: string; createdAt: string; updatedAt: string; } | null)[] | null | undefined' is not assignable to type 'Restaurant[]'.
  Type 'undefined' is not assignable to type 'Restaurant[]'.

29       this.restaurants = event.items;
         ~~~~~~~~~~~~~~~~

Error: src/main.ts:5:25 - error TS7016: Could not find a declaration file for module './aws-exports'. '/home/yadav/dev/tmp/amplify-app/src/aws-exports.js' implicitly has an 'any' type.

5 import aws_exports from "./aws-exports";
                          ~~~~~~~~~~~~~~~

After making these changes, there is still one more error I am unable to fix at the moment.


Error: src/app/app.component.ts:26:7 - error TS2322: Type '({ __typename: "Restaurant"; id: string; name: string; description: string; city: string; createdAt: string; updatedAt: string; } | null)[]' is not assignable to type 'Restaurant[]'.
  Type '{ __typename: "Restaurant"; id: string; name: string; description: string; city: string; createdAt: string; updatedAt: string; } | null' is not assignable to type 'Restaurant'.
    Type 'null' is not assignable to type 'Restaurant'.

26       this.restaurants = event.items;
         ~~~~~~~~~~~~~~~~

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
wlee221commented, Sep 22, 2021

Hi @rajinder-yadav, thanks for your detailed feedback! These issues are stemming from Angular 12 enforcing Typescript strict mode by default. I opened up #3606 to provide the necessary updates to the documentation, based on your suggestions (also confirmed locally 🎉 ).

1reaction
rajinder-yadavcommented, Jul 2, 2021

Here is the final fix in file app.components.ts, a typecast is required.

    this.api.ListRestaurants().then(event =>  {
      this.restaurants = (event.items as Array<Restaurant>);
    });

Please update the doc and have someone go through everything for Angular 12, the text is out of date and it’s really frustrating to learn like this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular Error Handling Best Practices - Medium
Learn about centralizing Angular error handling by implementing a global error handler, client and server errors, writing good error messages and more.
Read more >
Identify and Fix Build and Deployment Errors in Your Angular ...
In this guide, you will learn how to spot some of the most common build and deployment errors and how to resolve them...
Read more >
Typescripts Errors on Angular 12 with Material 12
I created a new angular 12 project and run it with angular material - no errors occured. Did u try to delete node_modules...
Read more >
ErrorHandler - Angular
The default implementation of ErrorHandler prints error messages to the console . To intercept error handling, write a custom exception handler that replaces ......
Read more >
Error Handling with Angular 8 - Tips and Best Practices - Rollbar
Handling errors properly is essential in building a robust application in Angular. Error handlers provide an opportunity to present friendly ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found