forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeature-flag.d.ts
More file actions
64 lines (60 loc) · 1.85 KB
/
Copy pathfeature-flag.d.ts
File metadata and controls
64 lines (60 loc) · 1.85 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* Keeps track of enabled features through interface declaration merging capabilities.
*/
export interface QuasarFeatureFlags {
[index: string]: boolean;
}
/**
* Helper to create flag-guards.
*
* Example: to enable 'ssr' types create a `ssr-flag.d.ts` with this content
*
* ```typescript
* // This import enable module augmentation instead of module overwrite
* import 'quasar';
*
* declare module 'quasar' {
* // This will be merged with other definitions
* // thanks to interface declaration merging
* interface QuasarFeatureFlags {
* ssr: true; // The object key is the feature flag name
* }
* }
* ```
*
* and flag-guard your types like this
*
* ```typescript
* type HasSsr<T, U> = IsFeatureEnabled<'ssr', T, U>;
* ```
*
* You can then use it like this for intersection types (where null type is `{}`)
*
* ```typescript
* type Intersection = {...} & HasSsr<{ ssrContext?: QSsrContext | null }, {}>;
* ```
*
* and like this for discriminated unions (where null type is `never`)
*
* ```typescript
* type Union = {...} | HasSsr<{ ssrContext?: QSsrContext | null }, never>;
* ```
*/
export type IsFeatureEnabled<
O extends string,
T,
U = {}
> = QuasarFeatureFlags[O] extends true ? T : U;
export type HasStore<T, U = {}> = IsFeatureEnabled<"store", T, U>;
export type HasSsr<T, U = {}> = IsFeatureEnabled<"ssr", T, U>;
export type HasSsg<T, U = {}> = IsFeatureEnabled<"ssg", T, U>;
export type HasSsrOrSsg<T, U = {}> = IsFeatureEnabled<
"ssr",
T,
IsFeatureEnabled<"ssg", T, U>
>;
export type HasPwa<T, U = {}> = IsFeatureEnabled<"pwa", T, U>;
export type HasCapacitor<T, U = {}> = IsFeatureEnabled<"capacitor", T, U>;
export type HasCordova<T, U = {}> = IsFeatureEnabled<"cordova", T, U>;
export type HasElectron<T, U = {}> = IsFeatureEnabled<"electron", T, U>;
export type HasBex<T, U = {}> = IsFeatureEnabled<"bex", T, U>;