angulartypescriptangular-routerlink

TS2322: Type 'number' is not assignable to type 'string'


I got this TS2322 error, when i tried to build my angular app.

I have a [link]="i" where i eq index number. When i declare it i use this: @Input() link!: string;

Link used by reference for routerLink like this: [routerLink]="link"

if i change link!: number, then i got this error: TS2322: Type 'number' is not assignable to type 'string | any[] | null | undefined'. for this part of the code: <a [routerLink]="link">

in my opinion routerLink needs string?!?! but than why is it triggerd, when i used link as string? any idea?


Solution

  • when you declare it as string, the value should be string only. In your case you can try passing i value as string [link]="'i'" or You can make @Input() link: any; to pass any type of value