Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Getting following
errors
:
error TS2345: Argument of type 'Menu' is not assignable to parameter of type '{ state: string; name: string; type: string; icon: string;
badge?: undefined; children?: undefine...'
the code:
import { Injectable } from '@angular/core';
export interface BadgeItem {
type: string;
value: string;
export interface ChildrenItems {
state: string;
name: string;
type?: string;
export interface Menu {
state: string;
name: string;
type: string;
icon: string;
badge?: BadgeItem[];
children?: ChildrenItems[];
const MENUITEMS = [
state: '/',
name: 'HOME',
type: 'link',
icon: 'explore'
state: 'account',
name: 'ACCOUNT',
type: 'sub',
icon: 'explore',
badge: [
{type: 'purple', value: 'new'}
children: [
{state: 'users', name: 'USERS'},
@Injectable()
export class MenuService {
getAll(): Menu[] {
return MENUITEMS;
add(menu: Menu) {
MENUITEMS.push(menu);
Any help will be highly appreciated.
–
–
Just specify the type of MENUITEMS
like below, the warning will go away
const MENUITEMS : Menu[] = [
state: '/',
name: 'HOME',
type: 'link',
icon: 'explore'
state: 'account',
name: 'ACCOUNT',
type: 'sub',
icon: 'explore',
badge: [
{type: 'purple', value: 'new'}
children: [
{state: 'users', name: 'USERS'},
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.