Skip to content

Inline task actions - strong types check#7851

Closed
ChristopherDedominici wants to merge 10 commits intomainfrom
add-inline-action
Closed

Inline task actions - strong types check#7851
ChristopherDedominici wants to merge 10 commits intomainfrom
add-inline-action

Conversation

@ChristopherDedominici
Copy link
Copy Markdown
Contributor

@ChristopherDedominici ChristopherDedominici commented Jan 8, 2026

Fixes #7560

Same as 7950, but here checks are mostly executed at type level

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jan 8, 2026

🦋 Changeset detected

Latest commit: 17f2db2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@nomicfoundation/hardhat-errors Patch
@nomicfoundation/hardhat-verify Patch
hardhat Patch

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

@ChristopherDedominici ChristopherDedominici added the no docs needed This PR doesn't require links to documentation label Jan 13, 2026
nextTaskArguments: TaskArguments,
currentIndex = this.actions.length - 1,
): Promise<any> => {
const currentTaskAction = this.actions[currentIndex];
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where the run command decides whether to run the action or the inlineAction, depending on which one is defined.

@kanej kanej requested a review from alcuadrado February 10, 2026 13:29
Copy link
Copy Markdown
Member

@alcuadrado alcuadrado left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some comments.

I think the main one is weather if the type complexity is worth it or not.

Also, this PR will need to update the config validation. The reason is that a user can provide a task definition that wasn't created with the builders, so we need to validate them.

/**
* A helper type to strictly enforce that plugins only use file-based actions.
*/
export type PluginSafeTaskDefinition =
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe let's call it just PluginTaskDefinition. The Safe part makes it a bit confusing.

}

export type TaskAction =
| { action: LazyActionObject<NewTaskActionFunction>; inlineAction?: never }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about renaming this to:

Suggested change
| { action: LazyActionObject<NewTaskActionFunction>; inlineAction?: never }
| { lazyAction: LazyActionObject<NewTaskActionFunction>; inlineAction?: never }

this way any error message will be more clear.

Copy link
Copy Markdown
Contributor Author

@ChristopherDedominici ChristopherDedominici Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but this will break current plugins, is this ok?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be a breaking change, so are we okay with that?

| MissingActionState
| ActionDefinedState
| DuplicateActionError = MissingActionState,
ActionTypeT extends "FILE" | "INLINE" | "NONE" = "NONE",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about something easier to read, like this? Again, because this may leak to type errors

Suggested change
ActionTypeT extends "FILE" | "INLINE" | "NONE" = "NONE",
ActionTypeT extends "LAZY_ACTION" | "INLINE_ACTION" | "MISSING_ACTION" = "MISSING_ACTION",

ActionTypeT extends "FILE" | "INLINE" | "NONE" = "NONE",
> {
/**
* Technical property needed to enforce the `ActionStateT` state check at compile time.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really needed? What happens if you omit it? I think a common name, at least in rust, would be Phantom: https://doc.rust-lang.org/std/marker/struct.PhantomData.html

TaskArgumentsT,
DuplicateActionError,
"FILE" | "INLINE"
>;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand this, but maybe it's too much? I think if the duplicated action doesn't fail at type-level, but fails immediately in the builder that's fine. It's a bug that you would catch in the very first run.

Same with missing action.

Removing them would simplify the code, at the expenses of only finding the error in the first run (I think that's fine), and adding some runtime validation in the builders and config validation.

Note that the validation is still needed, as the user may be using js.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would we loose anything else?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also applies for the other kind of task definitions

@ChristopherDedominici ChristopherDedominici changed the title Inline task actions Inline task actions - strong types check Feb 13, 2026
@ChristopherDedominici
Copy link
Copy Markdown
Contributor Author

@alcuadrado I created a separate PR where most of the checks have been modified to be runtime checks, see here (see here), so we can have a direct comparison between the two PRs.

@kanej kanej closed this Feb 19, 2026
@github-actions github-actions Bot mentioned this pull request Feb 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no docs needed This PR doesn't require links to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inline task actions

3 participants