This repository has been archived by the owner on Jan 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 925
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add assertAccountsExist function to @solana/accounts (#1995)
* Add assertAccountsExist function to @solana/accounts * Add assertAccountsExist to the accounts README
- Loading branch information
1 parent
a1fafee
commit ef2569b
Showing
4 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
packages/accounts/src/__typetests__/maybe-account-typetest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Address } from "@solana/addresses"; | ||
|
||
import { Account } from "../account"; | ||
import { assertAccountExists, assertAccountsExist,MaybeAccount } from "../maybe-account"; | ||
|
||
type MockData = { foo: 42 }; | ||
|
||
{ | ||
// It narrows a MaybeAccount to an Account | ||
const account = {} as unknown as MaybeAccount<MockData, '1111'>; | ||
assertAccountExists(account); | ||
account satisfies Account<MockData, '1111'>; | ||
} | ||
|
||
{ | ||
// It narrows an array of MaybeAccounts to an array of Accounts | ||
const accounts = [ | ||
{} as unknown as MaybeAccount<MockData, '1111'>, | ||
{} as unknown as MaybeAccount<MockData, '2222'>, | ||
{} as unknown as MaybeAccount<MockData, '3333'>, | ||
]; | ||
assertAccountsExist(accounts); | ||
accounts satisfies Account<MockData, Address>[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters