I am currently in the process of upgrading my Angular application to version 9. I have encountered an issue where everything runs smoothly when Ivy is disabled, but enabling Ivy causes the application's serve task to not finish correctly:
Here is a snippet from one of my components:
choosePlan(plan: IPlan) {
if (!this.isAddressValid()) {
this._toastService.error('Informe o seu CEP!', '', { positionClass: 'toast-top-right' });
} else {
this._actions$
.pipe(
ofActionSuccessful(this.addItem(plan)),
tap(() => this._clearUtms())
)
.subscribe(() => this._router.navigate([`/checkout/carrinho/${this.cart.id}`]));
}
}
Below is a section of my state management code:
@State<CartStateModel>({
name: 'cart',
defaults: {
cart: {},
},
})
@Injectable()
export class CartState {
@Action(Cart.AddItem)
addItem(ctx: StateContext<CartStateModel>, action: Cart.AddItem): Observable<ICart> {
const currentState = ctx.getState();
return zip(this.address$, this.shipping$).pipe(
mergeMap((obs: [IAddress, IShippingType]) =>
this._cartService.addItemToCart(
currentState.cart.id,
action.itemToAdd,
obs[0].cep,
obs[1].shippingMethodId
)
),
tap((cart: ICart) => ctx.setState({ cart: cart })),
take(1),
catchError((error: any) => throwError(error))
);
}
}
Lastly, here is a segment related to one of my actions:
export class Create {
static readonly type = '[Cart] Create';
constructor(public itemToAdd: ICartItemToAdd) {}
}
I am encountering some errors in my Typescript and Angular CLI:
: Compiled successfully.
ERROR in src/app/core/product/pages/product.component.ts:87:30 - error TS2345: Argument of type 'Create | AddItem' is not assignable to parameter of type 'ActionType'.
Type 'Create' is not assignable to type 'ActionType'.
Property 'type' is missing in type 'Create' but required in type '{ type: string; }'.
... (additional similar error messages)
The main issue centers around the Action type:
export namespace Cart {
export class Create {
static readonly type = '[Cart] Create';
constructor(public itemToAdd: ICartItemToAdd) {}
}
}
Removing the line 'static readonly type = '[Cart] Create';' eliminates one of the errors, but it is necessary for defining the type for Actions.
static readonly type = '[Cart] Create';
What steps should I follow to resolve these issues?
Thank you.