Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

177
Visualizações
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


let description: string= `This TypeScript string can 
span multiple 
lines
`;

let firstName: string = "Testing";
let title: string = "This is a testing page"
let profile: string = `I'm ${firstName}. 
${title}`;

console.log(profile);

let testArray: string[];

testArray=['Typescript','Gaming','Javascript','Python'];
console.log(testingArray);

let heading = document.createElement('h1');
heading.textContent = message;
let body = document.createElement('h2');
body.textContent = description;
let Name = document.createElement('h5');
Name.textContent = profile;
let testingArray = document.createElement('h5');
testingArray.textContent = testArray;
document.body.appendChild(heading);
document.body.appendChild(body);
document.body.appendChild(Name);
document.body.appendChild(testingArray); ```

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

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.

testingArray.textContent = testArray.join();

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

document.body.appendChild(heading);
document.body.appendChild(body);
document.body.appendChild(Name);
for(let testEle of testArray) {
    let testingArray = document.createElement('h5');
    testingArray.textContent = testEle;
    document.body.appendChild(testingArray);
}

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.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda