Open hugocaillard opened 1 year ago
The OpenAPI-to-typescript-client tooling isn't able to represent certain schemas as types. For many of them it will fallback to the object
type.
To workaround this, we also publish this library: https://www.npmjs.com/package/@stacks/stacks-blockchain-api-types. This uses tool that is able to generate more useful/accurate types for schemas.
Currently you need to explicitly cast the object types you get from the @stacks/blockchain-api-client
lib as the corresponding type from the @stacks/stacks-blockchain-api-types
lib.
Ok I see, thanks for clarifying @zone117x .
Do you know in which case the limitation occurs? For example, why does it impact
getAccountStxBalance(requestParameters: GetAccountStxBalanceRequest, initOverrides?: RequestInit): Promise<object>;
But others similar function have the right type:
getAccountBalance(requestParameters: GetAccountBalanceRequest, initOverrides?: RequestInit): Promise<AddressBalanceResponse>;
I'd be happy to investigate a bit if we think there's room for improvement here
Do you know in which case the limitation occurs?
IIRC the "json schema to typescript" tooling mentions some known limitations. You could take a look at the npm build scripts ran inside the /client
and /docs
directory to see the various tools used, for example the generate-openapi
command in /client/package.json
. In some cases it might be possible to modify the json schema in way to make the tooling happy.
It seems like I have outdated types with the
@stacks/blockchain-api-client
For example,AccountsApi.getAccountStxBalance
returnsPromise<object>
instead ofPromise<StxBalance>
I believe.I have this kind of issues in multiple places. Is it something wrong with the build or did I mess up somewhere?
Code here https://github.com/hirosystems/subnets-nft-demo/blob/606cb1477d9fa8bc75a8a34b50ccf243d1cb9a9e/src/stacks/apiCalls.ts#L53-L59