wardens 0.5.0 → 0.5.1-rc.0

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ### Fixed
10
+
11
+ - Added support for parametrized resources in `ResourceHandle<T>`.
12
+
9
13
  ## [0.5.0]
10
14
 
11
15
  ### Changed
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wardens",
3
- "version": "0.5.0",
3
+ "version": "0.5.1-rc.0",
4
4
  "description": "A framework for resource management",
5
5
  "type": "module",
6
6
  "main": "./dist/wardens.cjs",
@@ -1,4 +1,4 @@
1
- import { create, ResourceHandle } from '../';
1
+ import { create, ResourceContext, ResourceHandle } from '../';
2
2
 
3
3
  describe('Utility types', () => {
4
4
  describe('ResourceHandle', () => {
@@ -15,5 +15,18 @@ describe('Utility types', () => {
15
15
  hello: 'world',
16
16
  });
17
17
  });
18
+
19
+ it('infers the type when the value comes from a parameter', async () => {
20
+ async function Test(_ctx: ResourceContext, value: { count: number }) {
21
+ return {
22
+ value,
23
+ };
24
+ }
25
+
26
+ const test = await create(Test, { count: 2 });
27
+ expectTypeOf(test).toEqualTypeOf<ResourceHandle<typeof Test>>({
28
+ count: 2,
29
+ });
30
+ });
18
31
  });
19
32
  });
package/src/types.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
1
2
  import type ResourceContext from './resource-context';
2
3
 
3
4
  /**
@@ -25,6 +26,6 @@ export interface Resource<Value extends object> {
25
26
  }
26
27
 
27
28
  /** The `value` type returned when creating a resource. */
28
- export type ResourceHandle<Factory extends ResourceFactory<object>> = Awaited<
29
- ReturnType<Factory>
30
- >['value'];
29
+ export type ResourceHandle<
30
+ Factory extends ParametrizedResourceFactory<object, Array<any>>,
31
+ > = Awaited<ReturnType<Factory>>['value'];