My problem is related to Angular @Input() decorator, as when I am using this decorator, typescript throwing error, not when using in regular code.
In my child.component.ts file I am declaring this decorator to get props from parent component :
@Input() customColumns: {
name: string;
index: number;
type: 'icon' | 'image' | 'link' | 'button';
icon?: any;
url?: string;
}[] = [];
indexList: number[] = [];
And in my parent.component.ts file I am assigning the value for this variable like this :
customColumns = [
{ name: 'permissions', index: 7, type: 'icon', icon: faSave },
{ name: 'price list', index: 6, type: 'link', icon: faArrowDownWideShort },
{ name: 'details', index: 5, type: 'button', icon: faArrowUpWideShort },
];
Lastly, in my parent.component.html file I am calling that child component:
<app-child [customColumns]="customColumns">
</app-child>
But I'm getting this error:
Types of property 'type' are incompatible.
Type 'string' is not assignable to type '"button" | "link" | "image" | "icon"'.
But when I am doing same thing in normal typescript or ngOnInit() function it is working, can't figure out why it is happening, help me please, thanks in advance.
let customColumns: {
name: string;
index: number;
type: 'icon' | 'image' | 'link' | 'button';
icon?: any;
url?: string;
}[] = [];
customColumns = [
{ name: 'permissions', index: 7, type: 'link', icon: '' },
{
name: 'price list',
index: 6,
type: 'icon',
icon: faArrowDownWideShort,
},
{ name: 'details', index: 5, type: 'icon', icon: faArrowUpWideShort },
];
My project dependencies:
"@angular/cli": "~14.2.7", "typescript": "~4.7.2"