Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toString returns [Object object] #9

Open
AstaraelWeeper opened this issue Apr 10, 2019 · 7 comments
Open

toString returns [Object object] #9

AstaraelWeeper opened this issue Apr 10, 2019 · 7 comments

Comments

@AstaraelWeeper
Copy link

Hi, I'm using this in Ionic 4 and wasn't able to get the value of the GUID using .toString(), as it returns "[Object object]" as though it's using the normal toString instead of your class one, although hovering on it does indicate it uses the right one. using .toJSON also didn't work, as it said "is not a function".

I was only able to get the value using
var stringId = JSON.stringify(id);
var json =JSON.parse(stringId);

@Nifled
Copy link

Nifled commented Apr 23, 2019

Did you figure this out? If not, would you mind posting some of your code (where it evaluates to [Object object])? I was having some trouble with serialization but got it to work correctly, so I could help you out.

@Nifled
Copy link

Nifled commented Apr 23, 2019

@NicolasDeveloper Is this repo being maintained at all? There's not much on here but I can help out with issues and PRs.

@snico-dev
Copy link
Owner

So sorry, I didn't had time to fix it yet, but this week I'll do and update the npm

@gekkedev
Copy link
Contributor

@AstaraelWeeper I don't see how this is an error. Only if you call toString() on the Guid class without instantiating it. You may always call this method on objects and that is perfectly fine.

@GimmeDaKitty
Copy link

I have the exact same problem. I'm using Angular and I am passing the Guid as a parameter of the click function for the button, like this:

<button type="button" (click)="editFlight(flight.id)" class="btn btn-sm btn-light mr-1">Edit</button>
editFlight(id : Guid) {
    console.log(id.toString());
  }

Might be an Angular thing tho.

@kpenergy
Copy link

I think this seems to be a problem caused by deserialising JSON. Here's a small sample that produces this issue:

type MyType = {
    MyGuid: Guid;
}

const instance: MyType = {
    MyGuid: Guid.create()
}

// All good...
console.log(instance.MyGuid);
console.log(instance.MyGuid.toString());

const serialized = JSON.stringify(instance);
const deserialised: MyType = JSON.parse(serialized);

// Seems OK - outputs an object where `value` is a guid string
console.log(deserialised.MyGuid);

// Bad - outputs [object Object]
console.log(deserialised.MyGuid.toString());

To be honest, this issue renders the guid-typescript library unusable for me. I'm maybe missing something obvious, so if anyone can help me work past this I'd appreciate it.

@yannpiot
Copy link

To be honest, this issue renders the guid-typescript library unusable for me. I'm maybe missing something obvious, so if anyone can help me work past this I'd appreciate it.

What I resorted to do is refactor my code and store all GUIDs as plain strings. But I still use this library when I need to generate a GUID (immediately converting it to a string: var guidStr = Guid.create().toString()).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants