@@ -16,16 +16,15 @@ export type UnknownContext = Context<unknown>;
16
16
/**
17
17
* A helper type which can extract a Context value type from a Context type
18
18
*/
19
- export type ContextType < T extends UnknownContext > = T extends Context < infer Y >
20
- ? Y
21
- : never ;
19
+ export type ContextType < T extends UnknownContext > =
20
+ T extends Context < infer Y > ? Y : never ;
22
21
23
22
/**
24
23
* A function which creates a Context value object
25
24
*/
26
25
export function createContext < T > (
27
26
name : string ,
28
- initialValue ?: T
27
+ initialValue ?: T ,
29
28
) : Readonly < Context < T > > {
30
29
return {
31
30
name,
@@ -39,7 +38,7 @@ export function createContext<T>(
39
38
*/
40
39
export type ContextCallback < ValueType > = (
41
40
value : ValueType ,
42
- unsubscribe ?: ( ) => void
41
+ unsubscribe ?: ( ) => void ,
43
42
) => void ;
44
43
45
44
/**
@@ -56,18 +55,24 @@ export class ContextEvent<T extends UnknownContext> extends Event {
56
55
public constructor (
57
56
public readonly context : T ,
58
57
public readonly callback : ContextCallback < ContextType < T > > ,
59
- public readonly subscribe ?: boolean
58
+ public readonly subscribe ?: boolean ,
60
59
) {
61
60
super ( "context-request" , { bubbles : true , composed : true } ) ;
62
61
}
63
62
}
64
63
64
+ /**
65
+ * A 'context-request' event can be emitted by any element which desires
66
+ * a context value to be injected by an external provider.
67
+ */
65
68
declare global {
69
+ interface WindowEventMap {
70
+ "context-request" : ContextEvent < UnknownContext > ;
71
+ }
72
+ interface ElementEventMap {
73
+ "context-request" : ContextEvent < UnknownContext > ;
74
+ }
66
75
interface HTMLElementEventMap {
67
- /**
68
- * A 'context-request' event can be emitted by any element which desires
69
- * a context value to be injected by an external provider.
70
- */
71
76
"context-request" : ContextEvent < UnknownContext > ;
72
77
}
73
78
}
0 commit comments