Comments (2)
that's fantastic - nice and clean 👍
from jsonrpc-ts.
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 beany
anyway.
Hope this covers your needs :)
from jsonrpc-ts.
Related Issues (7)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsonrpc-ts.