Skip to content

Commit

Permalink
Add TS overrides for getNfts for with and without metadata (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
thebrianchen authored Mar 16, 2022
1 parent 21d823c commit 7cb9852
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ export interface AlchemyMethods {
params: GetNftMetadataParams,
callback?: Web3Callback<GetNftMetadataResponse>,
): Promise<GetNftMetadataResponse>;
getNfts(
params: GetNftsParams | GetNftsParamsWithoutMetadata,
callback?: Web3Callback<GetNftsResponse | GetNftsResponseWithoutMetadata>,
): Promise<GetNftsResponse | GetNftsResponseWithoutMetadata>;
getNfts(
params: GetNftsParamsWithoutMetadata,
callback?: Web3Callback<GetNftsResponseWithoutMetadata>,
): Promise<GetNftsResponseWithoutMetadata>;
getNfts(
params: GetNftsParams,
callback?: Web3Callback<GetNftsResponse>,
): Promise<GetNftsResponse>;
getTransactionReceipts(
params: TransactionReceiptsParams,
callback?: Web3Callback<TransactionReceiptsResponse>,
Expand Down Expand Up @@ -151,6 +151,30 @@ export function createAlchemyWeb3(
);
};
alchemyWeb3.setWriteProvider = setWriteProvider;

// Define function separately in order to allow for overloads.
function getNfts(
params: GetNftsParamsWithoutMetadata,
callback?: Web3Callback<GetNftsResponseWithoutMetadata>,
): Promise<GetNftsResponseWithoutMetadata>;
function getNfts(
params: GetNftsParams,
callback?: Web3Callback<GetNftsResponse>,
): Promise<GetNftsResponse>;
function getNfts(
params: GetNftsParams | GetNftsParamsWithoutMetadata,
callback?:
| Web3Callback<GetNftsResponseWithoutMetadata>
| Web3Callback<GetNftsResponse>,
): Promise<GetNftsResponse | GetNftsResponseWithoutMetadata> {
return callAlchemyRestEndpoint({
restSender,
callback,
params,
path: "/v1/getNFTs/",
});
}

alchemyWeb3.alchemy = {
getTokenAllowance: (params: TokenAllowanceParams, callback) =>
callAlchemyJsonRpcMethod({
Expand Down Expand Up @@ -200,13 +224,7 @@ export function createAlchemyWeb3(
params,
path: "/v1/getNFTMetadata/",
}),
getNfts: (params: GetNftsParams | GetNftsParamsWithoutMetadata, callback) =>
callAlchemyRestEndpoint({
restSender,
callback,
params,
path: "/v1/getNFTs/",
}),
getNfts,
getTransactionReceipts: (params: TransactionReceiptsParams, callback) =>
callAlchemyJsonRpcMethod({
jsonRpcSenders,
Expand Down

0 comments on commit 7cb9852

Please sign in to comment.