wardens 0.6.0-rc.3 → 0.6.0-rc.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -0
- package/package.json +1 -1
- package/src/__tests__/utility-types.test-d.ts +25 -1
- package/src/index.ts +1 -1
- package/src/utility-types.ts +5 -0
package/CHANGELOG.md
CHANGED
@@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
9
9
|
### Added
|
10
10
|
|
11
11
|
- New context API carries state down the tree without plumbing through arguments.
|
12
|
+
- New `ContextType<Handle>` utility type which gets the value type of a context.
|
12
13
|
|
13
14
|
### Changed
|
14
15
|
|
package/package.json
CHANGED
@@ -1,4 +1,10 @@
|
|
1
|
-
import {
|
1
|
+
import {
|
2
|
+
create,
|
3
|
+
ResourceScope,
|
4
|
+
ResourceHandle,
|
5
|
+
createContext,
|
6
|
+
ContextType,
|
7
|
+
} from '../';
|
2
8
|
|
3
9
|
describe('Utility types', () => {
|
4
10
|
describe('ResourceHandle', () => {
|
@@ -29,4 +35,22 @@ describe('Utility types', () => {
|
|
29
35
|
});
|
30
36
|
});
|
31
37
|
});
|
38
|
+
|
39
|
+
describe('ContextType', () => {
|
40
|
+
it('returns the type contained in context', async () => {
|
41
|
+
const Context = createContext(() => ({
|
42
|
+
hello: 'world',
|
43
|
+
}));
|
44
|
+
|
45
|
+
async function Test({ getContext }: ResourceScope) {
|
46
|
+
return { value: getContext(Context) };
|
47
|
+
}
|
48
|
+
|
49
|
+
const value = await create(Test);
|
50
|
+
|
51
|
+
expectTypeOf(value).toEqualTypeOf<ContextType<typeof Context>>({
|
52
|
+
hello: 'any string, really',
|
53
|
+
});
|
54
|
+
});
|
55
|
+
});
|
32
56
|
});
|
package/src/index.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
export { default as bindContext } from './bind-context';
|
2
2
|
export { createRoot as create, destroyRoot as destroy } from './root-lifecycle';
|
3
3
|
export { createContext } from './inherited-context';
|
4
|
-
export type { Resource, ResourceHandle } from './utility-types';
|
4
|
+
export type { Resource, ResourceHandle, ContextType } from './utility-types';
|
5
5
|
export type { default as ResourceScope } from './resource-scope';
|
package/src/utility-types.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
2
|
+
import type { ContextHandle } from './inherited-context';
|
2
3
|
import type ResourceScope from './resource-scope';
|
3
4
|
|
4
5
|
/**
|
@@ -29,3 +30,7 @@ export interface Resource<Value extends object> {
|
|
29
30
|
export type ResourceHandle<
|
30
31
|
Factory extends ParametrizedResourceFactory<object, Array<any>>,
|
31
32
|
> = Awaited<ReturnType<Factory>>['value'];
|
33
|
+
|
34
|
+
/** The type returned when you call `getContext`. */
|
35
|
+
export type ContextType<Handle extends ContextHandle<unknown>> =
|
36
|
+
Handle extends ContextHandle<infer Value> ? Value : never;
|