Giter VIP home page Giter VIP logo

Comments (2)

tbrannam avatar tbrannam commented on August 26, 2024 1

that's fantastic - nice and clean 👍

from jsonrpc-ts.

shekohex avatar shekohex commented on August 26, 2024

Hi @tbrannam, i just published a new version 0.2.0 which supports the following:

  • Auto Infer return type of a method, if not then fallback to any
    for example
// here is a simple math service
interface MathService {
  // a method called sum that accepts 2 args of type number
  sum: [number, number];
  // or if you need return type, you can have that too :)
  sumWithReturnType: ({ x, y }: { x: number; y: number }) => number;
}

take a look at

sumWithReturnType: ({ x, y }: { x: number; y: number }) => number;
// -------------------------------------------------------^^^^^^^

then the return type of the result response will be infrared to be number

// response.data.result has type of number :)
const response = await rpcClient.makeRequest({
  method: 'sumWithReturnType',
  params: { x: 3, y: 2 },
  id: 2,
  jsonrpc: '2.0',
});

also notice that you don't even need to type the method name here in the mackeRequest<'blahblah'>
it just got inferred from the method key.

by the way, the old method works too, but instead there is no need anymore for the TResponse i removed it completely, because it get inferred to be any anyway.

Hope this covers your needs :)

from jsonrpc-ts.

Related Issues (7)

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.