Skip to content
Advertisement

Typescript Arrays

i am learning some Typescript and i am putting everthing i learn in a single page I keep encountering this error called

Type ‘string[]’ is not assignable to type ‘string’.ts(2322)

but it still shows the array on the liveserver LiveServer

Will this affect the code or can i ignore?

this is my code

JavaScript

Advertisement

Answer

The type of textContent is a string and you are storing an array of strings. So the error is right. You need to convert the array to string using methods like join.

JavaScript

Or create multiple textContent by looping over the array, anything according to your logic.

JavaScript

Will this affect the code or can i ignore?

Well I would say not to ignore, as ignoring didn’t help me run it successfully in other live servers like StackBlitz.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement