diff --git a/ember-resources/src/function-based/types.ts b/ember-resources/src/function-based/types.ts index a026dc38d..289db3fef 100644 --- a/ember-resources/src/function-based/types.ts +++ b/ember-resources/src/function-based/types.ts @@ -131,7 +131,7 @@ export type ResourceFunction = (hooks: ResourceAPI) => Value | * of the resource is the result of the collapsed functions * passed to `resource` */ -export type ResourceFn = (hooks: ResourceAPI) => Value; +export type ResourceFn = Value & ((hooks: ResourceAPI) => Value); export type Destructor = () => void; export type Cache = object; diff --git a/test-app/app/components/implicit-current.gts b/test-app/app/components/implicit-current.gts index 4ba106311..933a6cfec 100644 --- a/test-app/app/components/implicit-current.gts +++ b/test-app/app/components/implicit-current.gts @@ -17,5 +17,6 @@ export const Now = resource(({ on }) => { diff --git a/test-app/tests/core/implicit-current-test.gts b/test-app/tests/core/implicit-current-test.gts new file mode 100644 index 000000000..5dcd0fbff --- /dev/null +++ b/test-app/tests/core/implicit-current-test.gts @@ -0,0 +1,38 @@ +import { on } from '@ember/modifier'; +import { click, render, settled } from '@ember/test-helpers'; +import { module, test } from 'qunit'; +import { setupRenderingTest } from 'ember-qunit'; + +import { cell, resource, resourceFactory } from 'ember-resources'; + + +module('.current and implicit .current', function (hooks) { + setupRenderingTest(hooks); + + test('A resource has a current property', async function (assert) { + let change = () => 0; + const Now = resource(() => { + const now = cell(0); + + change = () => now.current++; + + return now; + }); + + await render( + + ); + + assert.dom('#implicit').hasText('0'); + assert.dom('explicit').hasText('0'); + + change(); + await settled(); + + assert.dom('#implicit').hasText('1'); + assert.dom('explicit').hasText('1'); + }); +}); diff --git a/test-app/tests/type-tests/function-based.ts b/test-app/tests/type-tests/function-based.ts index f96e01f92..d11cb3401 100644 --- a/test-app/tests/type-tests/function-based.ts +++ b/test-app/tests/type-tests/function-based.ts @@ -1,4 +1,5 @@ import { resource } from 'ember-resources'; +import { expectTypeOf } from 'expect-type'; import { expectType } from 'ts-expect'; /* @@ -13,3 +14,6 @@ import { expectType } from 'ts-expect'; */ expectType(resource(() => 'hi')); expectType(resource(() => () => 'hi')); + +expectTypeOf(resource(() => 'hi')).toMatchTypeOf(); +expectTypeOf(resource(() => 'hi')).toMatchTypeOf>();