forked from canonical/juju-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.ts
41 lines (34 loc) · 1.1 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import type { PayloadAction } from "@reduxjs/toolkit";
import type { Action, UnknownAction } from "redux";
import { isAction } from "redux";
import type { Config } from "store/general/types";
export type WindowConfig = Omit<Config, "authMethod">;
declare global {
interface Window {
jujuDashboardConfig?: WindowConfig;
}
}
/*
* This type can be used for React props where a component needs to provide the
* props from either A or B, but prevent a mix of both.
*/
export type ExclusiveProps<A, B> =
| (A & Partial<Record<keyof B, never>>)
| (B & Partial<Record<keyof A, never>>);
/*
This typeguard can be used to check if a Redux action includes a payload.
*/
export const isPayloadAction = (
action: UnknownAction,
): action is PayloadAction<Record<string, unknown>> =>
isAction(action) &&
"payload" in action &&
!!action.payload &&
typeof action.payload === "object";
export const isSpecificAction = <A extends Action>(
action: UnknownAction,
actionType: string,
): action is A => isPayloadAction(action) && action.type === actionType;
export enum FeatureFlags {
REBAC = "rebac",
}