简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM