This Banner is For Sale !!
Get your ad here for a week in 20$ only and get upto 15k traffic Daily!!!

Paracetamol.ts💊| #33: Explica este código TypeScript




Explica este código TypeScript




Dificultad: Avanzado

¿Cómo podría hacer que set solo acepte cadenas de texto?

const set = new Set();
set.add("El sabor de las cerezas");
set.add("El origen");
set.add(2222); // este valor no debería ser aceptado
Enter fullscreen mode

Exit fullscreen mode

  • A. const set = new Set:string()
  • B. const set = new Set():string;
  • C. const set = String(new Set())
  • D. const set = new Set<string>()
  • E. No se puede crear un Set que sea solo de un tipo
Respuesta

✅ D. const set = new Set<string>()

Para crear un Set que sea solo de un valor, podemos usar la sintaxis de los genericos, envolviendo entre <> el valor que queremos, en este caso, string.


The Article was Inspired from tech community site.
Contact us if this is inspired from your article and we will give you credit for it for serving the community.

This Banner is For Sale !!
Get your ad here for a week in 20$ only and get upto 10k Tech related traffic daily !!!

Leave a Reply

Your email address will not be published. Required fields are marked *

Want to Contribute to us or want to have 15k+ Audience read your Article ? Or Just want to make a strong Backlink?