Add planType to distinguish between InstructionPlan, TransactionPlan and TransactionPlanResult#1309
Conversation
🦋 Changeset detectedLatest commit: 6711d7a The changes in this PR will be included in the next version bump. This PR includes changesets to release 43 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
BundleMonFiles updated (4)
Unchanged files (132)
Total files change +677B +0.17% Final result: ✅ View report in BundleMon website ➡️ |
|
Documentation Preview: https://kit-docs-o7rfhauv4-anza-tech.vercel.app |
mcintyre94
left a comment
There was a problem hiding this comment.
Looks great! I prefer an explicit extra key like this to changing the name of kind for each one because I think it's clearer.
…Plan` and `TransactionPlanResult`
abbe5f1 to
91cdb71
Compare
003dc4e to
6711d7a
Compare
|
🔎💬 Inkeep AI search and chat service is syncing content for source 'Solana Kit Docs' |
|
Because there has been no activity on this PR for 14 days since it was merged, it has been automatically locked. Please open a new issue if it requires a follow up. |

Problem
There is currently now way to distinguish between
InstructionPlan,TransactionPlanandTransactionPlanResulttypes without inspecting the whole tree structure recursively and identifying the types of their leaves.Summary of Changes
This PR adds a new
planTypeproperty to allInstructionPlan,TransactionPlan, andTransactionPlanResulttypes to distinguish them from each other at runtime. This property is a string literal with the value'instructionPlan','transactionPlan', or'transactionPlanResult'respectively.This PR also adds new type guard functions that make use of that new property:
isInstructionPlan,isTransactionPlan, andisTransactionPlanResult.This means a function can now request an argument such as
InstructionPlan | TransactionPlanand distinguish between them to tackle them differently. This will be useful in our instruction plan Kit Plugins as it will allow consumers to also passTransactionPlansand skip the planning phase.Alternatives
I went with
planTypefor the discriminator because we already havekindto distinguish between the different kinds of plans inside a tree structure. Do let me know if{ planType, kind }is clear enough as a "discriminator pair".Alternatively, instead of
{ planType, kind }we could have a differentkindname depending on the type of plan. For instance,instructionPlanKind,transactionPlanKindandtransactionPlanResultKind. The property key would then be used to distinguish the plan types and the value to distinguish between the different structures inside that plan type.