Add initial ActionState type

This commit is contained in:
Michael B. Gale
2026-06-30 12:59:35 +01:00
parent e1905475d1
commit 9b35ab94e1

37
src/action-common.ts Normal file
View File

@@ -0,0 +1,37 @@
import { Env } from "./environment";
import { FeatureEnablement } from "./feature-flags";
import { Logger } from "./logging";
/** Describes different state features that an Action may have. */
export interface FeatureState {
Logger: {
/** The logger that is in use. */
logger: Logger;
};
Env: {
/** Information about environment variables. */
env: Env;
};
FeatureFlags: {
/** Information about enabled feature flags. */
features: FeatureEnablement;
};
}
/** Identifies a type of state an Action may have. */
export type StateFeature = keyof FeatureState;
/** Constructs the union of all state types identifies by `Fs`. */
export type FieldsOf<Fs extends readonly StateFeature[]> = Fs extends [
infer Head extends StateFeature,
]
? FeatureState[Head]
: Fs extends [
infer Head extends StateFeature,
...infer Tail extends StateFeature[],
]
? FeatureState[Head] & FieldsOf<Tail>
: never;
/** Describes the state of an Action that has access to the state corresponding to `Fs`. */
export type ActionState<Fs extends readonly StateFeature[]> = FieldsOf<Fs>;