Skip to content

Commit 9b35ab9

Browse files
committed
Add initial ActionState type
1 parent e190547 commit 9b35ab9

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

src/action-common.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { Env } from "./environment";
2+
import { FeatureEnablement } from "./feature-flags";
3+
import { Logger } from "./logging";
4+
5+
/** Describes different state features that an Action may have. */
6+
export interface FeatureState {
7+
Logger: {
8+
/** The logger that is in use. */
9+
logger: Logger;
10+
};
11+
Env: {
12+
/** Information about environment variables. */
13+
env: Env;
14+
};
15+
FeatureFlags: {
16+
/** Information about enabled feature flags. */
17+
features: FeatureEnablement;
18+
};
19+
}
20+
21+
/** Identifies a type of state an Action may have. */
22+
export type StateFeature = keyof FeatureState;
23+
24+
/** Constructs the union of all state types identifies by `Fs`. */
25+
export type FieldsOf<Fs extends readonly StateFeature[]> = Fs extends [
26+
infer Head extends StateFeature,
27+
]
28+
? FeatureState[Head]
29+
: Fs extends [
30+
infer Head extends StateFeature,
31+
...infer Tail extends StateFeature[],
32+
]
33+
? FeatureState[Head] & FieldsOf<Tail>
34+
: never;
35+
36+
/** Describes the state of an Action that has access to the state corresponding to `Fs`. */
37+
export type ActionState<Fs extends readonly StateFeature[]> = FieldsOf<Fs>;

0 commit comments

Comments
 (0)