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. */ /** Describes different state features that an Action may have. */
export interface FeatureState { export interface FeatureState {
Base: BaseState;
Logger: { Logger: {
/** The logger that is in use. */ /** The logger that is in use. */
logger: Logger; logger: Logger;
@@ -52,7 +53,7 @@ export type StateFeature = keyof FeatureState;
/** Constructs the intersection of all state types identifies by `Fs`. */ /** Constructs the intersection of all state types identifies by `Fs`. */
export type FieldsOf<Fs extends readonly StateFeature[]> = Fs extends [] export type FieldsOf<Fs extends readonly StateFeature[]> = Fs extends []
? BaseState ? Record<never, never>
: Fs extends [ : Fs extends [
infer Head extends StateFeature, infer Head extends StateFeature,
...infer Tail extends readonly 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. * Each Action can then augment the `state` further if additional features are required.
*/ */
export type ActionMain = ( export type ActionMain = (
state: ActionState<["Logger", "Env", "Actions"]>, state: ActionState<["Base", "Logger", "Env", "Actions"]>,
) => Promise<void>; ) => Promise<void>;
/** A specification for a CodeQL Action step. */ /** 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); 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 // To capture errors appropriately, keep as much code within the try-catch as
// possible, and only use safe functions outside. // 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 // To capture errors appropriately, keep as much code within the try-catch as
// possible, and only use safe functions outside. // 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 // To capture errors appropriately, keep as much code within the try-catch as
// possible, and only use safe functions outside. // possible, and only use safe functions outside.

View File

@@ -90,7 +90,7 @@ async function sendCompletedStatusReport(
async function run({ async function run({
startedAt, startedAt,
logger, logger,
}: ActionState<["Logger"]>): Promise<void> { }: ActionState<["Base", "Logger"]>): Promise<void> {
// To capture errors appropriately, keep as much code within the try-catch as // To capture errors appropriately, keep as much code within the try-catch as
// possible, and only use safe functions outside. // 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`. */ /** For testing purposes, we make all available state features accessible in `TestEnv`. */
type AllState = [ type AllState = [
"Base",
"Logger", "Logger",
"Env", "Env",
"ReadOnlyEnv", "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 // To capture errors appropriately, keep as much code within the try-catch as
// possible, and only use safe functions outside. // possible, and only use safe functions outside.
try { try {