Coder Social home page Coder Social logo

Comments (6)

angelnikolov avatar angelnikolov commented on June 25, 2024

Can you try calling .toString() on the id, before calling the method? I think the issue is because the cacheable decorator does not know that it needs to call the toString method on the Guid object to extract the actual guid.

from ts-cacheable.

dscheibe avatar dscheibe commented on June 25, 2024

Yes, i just did that for the id : string parameter type example before passing it to the method and it works fine. Passing it as id : Guid to the method displays the object with @Cacheable in the debugger like that:

{value: "143dffe4-fe9e-40fb-ad49-673f8850bff5"}

So it is still correct but since the type has changed to object the toString() method won't work anymore and using Typescript i can't do neither of the two (the latter obviously won't compile due to value being private in Guid):

@Cacheable()
  getUser(id:Guid) {
    return this.http
    .get(`api/users/${id.toString()}`);
  }
@Cacheable()
  getUser(id:Guid) {
    return this.http
    .get(`api/users/${id.value}`);
  }

Do you see a way having the type of Guid remain a real Guid type instead of object?

from ts-cacheable.

angelnikolov avatar angelnikolov commented on June 25, 2024

I reproduced your use case and it's indeed a bit tricky. However, isn't calling toString before passing it to the method not a solution for you?

from ts-cacheable.

dscheibe avatar dscheibe commented on June 25, 2024

Sure, it's not the end of the world, but i don't want to change too much of my API, so this is a viable solution for now (which let's me keep my interfaces the same way):

getUser(id:Guid) {
  return this.getUserInternal(id.toString());
}

@Cacheable()
private getUserInternal(id:string) {
  return this.http
  .get(`api/users/${id}`);
}

Maybe you can make it work in a future version, if it is not too tricky... :)

from ts-cacheable.

angelnikolov avatar angelnikolov commented on June 25, 2024

The issue is that pass the parameters through a JSON.parse(JSON.stringify(parameters)) so we make a deep copy of those because of #7 which is also a valid issue. Let me think about it.

from ts-cacheable.

dscheibe avatar dscheibe commented on June 25, 2024

I see, thanks for taking the time, much appreciated :)

from ts-cacheable.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.