Require BaseState to be declared explicitly

This commit is contained in:
Michael B. Gale
2026-07-14 10:12:44 +01:00
parent 2dbfdcaa83
commit 2f9048cfbd
7 changed files with 11 additions and 7 deletions

View File

@@ -22,6 +22,7 @@ export interface BaseState {
/** Describes different state features that an Action may have. */
export interface FeatureState {
Base: BaseState;
Logger: {
/** The logger that is in use. */
logger: Logger;
@@ -52,7 +53,7 @@ export type StateFeature = keyof FeatureState;
/** Constructs the intersection of all state types identifies by `Fs`. */
export type FieldsOf<Fs extends readonly StateFeature[]> = Fs extends []
? BaseState
? Record<never, never>
: Fs extends [
infer Head extends StateFeature,
...infer Tail extends readonly StateFeature[],
@@ -68,7 +69,7 @@ export type ActionState<Fs extends readonly StateFeature[]> = FieldsOf<Fs>;
* Each Action can then augment the `state` further if additional features are required.
*/
export type ActionMain = (
state: ActionState<["Logger", "Env", "Actions"]>,
state: ActionState<["Base", "Logger", "Env", "Actions"]>,
) => Promise<void>;
/** A specification for a CodeQL Action step. */

View File

@@ -212,7 +212,7 @@ async function runAutobuildIfLegacyGoWorkflow(config: Config, logger: Logger) {
await runAutobuild(config, BuiltInLanguage.go, logger);
}
async function run({ startedAt, logger }: ActionState<["Logger"]>) {
async function run({ startedAt, logger }: ActionState<["Base", "Logger"]>) {
// To capture errors appropriately, keep as much code within the try-catch as
// possible, and only use safe functions outside.

View File

@@ -68,7 +68,7 @@ async function sendCompletedStatusReport(
}
}
async function run({ startedAt, logger }: ActionState<["Logger"]>) {
async function run({ startedAt, logger }: ActionState<["Base", "Logger"]>) {
// To capture errors appropriately, keep as much code within the try-catch as
// possible, and only use safe functions outside.

View File

@@ -203,7 +203,9 @@ async function sendCompletedStatusReport(
}
}
async function run(actionState: ActionState<["Logger", "Env", "Actions"]>) {
async function run(
actionState: ActionState<["Base", "Logger", "Env", "Actions"]>,
) {
// To capture errors appropriately, keep as much code within the try-catch as
// possible, and only use safe functions outside.

View File

@@ -90,7 +90,7 @@ async function sendCompletedStatusReport(
async function run({
startedAt,
logger,
}: ActionState<["Logger"]>): Promise<void> {
}: ActionState<["Base", "Logger"]>): Promise<void> {
// To capture errors appropriately, keep as much code within the try-catch as
// possible, and only use safe functions outside.

View File

@@ -194,6 +194,7 @@ export function getTestActionsEnv(): ActionsEnv {
/** For testing purposes, we make all available state features accessible in `TestEnv`. */
type AllState = [
"Base",
"Logger",
"Env",
"ReadOnlyEnv",

View File

@@ -54,7 +54,7 @@ async function sendSuccessStatusReport(
}
}
async function run({ startedAt, logger }: ActionState<["Logger"]>) {
async function run({ startedAt, logger }: ActionState<["Base", "Logger"]>) {
// To capture errors appropriately, keep as much code within the try-catch as
// possible, and only use safe functions outside.
try {