Skip to content

Commit 735f543

Browse files
committed
wip
1 parent 81a90ce commit 735f543

File tree

6 files changed

+14
-8
lines changed

6 files changed

+14
-8
lines changed

ember-resources/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"start": "pnpm vite build --watch",
3939
"build": "pnpm vite build",
4040
"lint": "concurrently 'npm:lint:*(!fix)' --names 'lint:'",
41+
"lint:types": "tsc --noEmit",
4142
"lint:fix": "concurrently 'npm:lint:*:fix' --names 'fix:'",
4243
"lint:js": "eslint . --cache",
4344
"lint:prettier": "prettier --check '**/*.{js,ts}'",

ember-resources/src/function-based/resource.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { ResourceManagerFactory } from './manager.ts';
77
import { INTERNAL } from './types.ts';
88
import { wrapForPlainUsage } from './utils.ts';
99

10-
import type { InternalFunctionResourceConfig, ResourceFn, ResourceFunction } from './types.ts';
10+
import type { InternalFunctionResourceConfig, Resource, ResourceFunction } from './types.ts';
1111

1212
const TYPE = 'function-based';
1313

@@ -111,7 +111,7 @@ registerUsable(TYPE, (context: object, config: InternalFunctionResourceConfig) =
111111
* </template>
112112
* ```
113113
*/
114-
export function resource<Value>(setup: ResourceFunction<Value>): Value;
114+
export function resource<Value>(setup: ResourceFunction<Value>): Resource<Value>;
115115

116116
/**
117117
* `resource` is an alternative API to the class-based `Resource`.
@@ -167,14 +167,14 @@ export function resource<Value>(setup: ResourceFunction<Value>): Value;
167167
* }
168168
* ```
169169
*/
170-
export function resource<Value>(context: object, setup: ResourceFunction<Value>): Value;
170+
export function resource<Value>(context: object, setup: ResourceFunction<Value>): Resource<Value>;
171171

172172
/**
173173
*/
174174
export function resource<Value>(
175175
context: object | ResourceFunction<Value>,
176176
setup?: ResourceFunction<Value>,
177-
): Value | InternalFunctionResourceConfig<Value> | ResourceFn<Value> {
177+
): Value | InternalFunctionResourceConfig<Value> | Resource<Value> {
178178
if (!setup) {
179179
assert(
180180
`When using \`resource\` with @use, ` +
@@ -205,7 +205,7 @@ export function resource<Value>(
205205
* using vanilla functions as resources without the resource wrapper
206206
*
207207
*/
208-
return internalConfig as unknown as ResourceFn<Value>;
208+
return internalConfig as unknown as Resource<Value>;
209209
}
210210

211211
assert(

ember-resources/src/function-based/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,11 @@ export type ResourceFunction<Value = unknown> = (hooks: ResourceAPI) => Value |
131131
* of the resource is the result of the collapsed functions
132132
* passed to `resource`
133133
*/
134-
export type ResourceFn<Value = unknown> = Value & ((hooks: ResourceAPI) => Value);
134+
export interface Invokable<Value = unknown> extends Reactive<Value> {
135+
(hooks: ResourceAPI): Value;
136+
}
137+
138+
export type Resource<Value = unknown> = Value & Invokable<Value>;
135139

136140
export type Destructor = () => void;
137141
export type Cache = object;

ember-resources/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ export { registerUsable, use } from './use.ts';
55

66
// Public Type Utilities
77
export type { ResourceAPI } from './function-based/index.ts';
8-
export type { Reactive } from './function-based/types.ts';
8+
export type { Reactive, Resource } from './function-based/types.ts';

test-app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
},
1313
"scripts": {
1414
"lint": "concurrently 'npm:lint:*(!fix)' --names 'lint:'",
15+
"lint:types": "glint",
1516
"lint:fix": "concurrently 'npm:lint:*:fix' --names 'fix:'",
1617
"lint:hbs": "ember-template-lint . --no-error-on-unmatched-pattern",
1718
"lint:js": "eslint . --cache",

test-app/tests/type-tests/function-based.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { resource } from 'ember-resources';
1+
import { type Resource, resource } from 'ember-resources';
22
import { expectTypeOf } from 'expect-type';
33
import { expectType } from 'ts-expect';
44

0 commit comments

Comments
 (0)