Skip to content

Commit

Permalink
update example
Browse files Browse the repository at this point in the history
  • Loading branch information
namgold committed Dec 15, 2023
1 parent f16db06 commit 2ec73fd
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/utils/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ const ValidateBalanceExample = isArray(
result: isNullable(isArray(isString)),
}),
)

const ValidateComplexResponseExample = isStruct({
data: isStruct({
wallets: isArray(
Expand All @@ -90,6 +89,15 @@ const ValidateComplexResponseExample = isStruct({
}),
}),
})

type ExtractedBalances = GuardedType<typeof ValidateBalanceExample>

let complexResponseExample: any
if (ValidateComplexResponseExample(complexResponseExample)) {
// `complexResponseExample` has been generated type now. You can try:
type Wallets = typeof complexResponseExample.data.wallets
const balance: ExtractedBalances | null | undefined = complexResponseExample.data.wallets[0].balances
} else {
// complexResponseExample is unknown type
complexResponseExample
}
/* eslint-enable @typescript-eslint/no-unused-vars */

0 comments on commit 2ec73fd

Please sign in to comment.