Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

Typescript object changes when pushed into an array

$
0
0

I have something very strange happening...I have an array called destinations which takes objects with a dest, an amount and a memo.

My code is the following:

  • I have a variable "element" which (when logged to the console) is a string with value "xNUSrBmqocfTinhSZVV6vLtwzaWasCoYuTUqnERPYjd8CAj3TtAf3hTvsNzoeYRY5b4qFGBS4mZhpXiJDghMKMGuJeD4Qy74ZCe9oMreUuwcRKQVKjj55LUEbnSDPtzH71gyPuT1ft3"
  • But when I create an object and set the dest to this variable and push this object into the destinations array, it suddenly isn't the string above anymore but an object... (take a look at the attached screenshot to see the outputs of the console.logs)
const destinations: { dest: string | never[]; amount: number; memo: string; }[] = [];console.log("ELEMENT")console.log(element)console.log("-----")destinations.push(    {        dest: element,        amount: 1 * 1e8,        memo: JSON.stringify(poll),     }) console.log("DESTINATIONS")console.log(destinations)console.log("-----")

enter image description here

Why is this happening?

Thanks in advance


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>