diff --git a/ember-resources/src/function-based/types.ts b/ember-resources/src/function-based/types.ts index 5ee72b371..2333ac366 100644 --- a/ember-resources/src/function-based/types.ts +++ b/ember-resources/src/function-based/types.ts @@ -10,7 +10,7 @@ export interface InternalFunctionResourceConfig { [INTERNAL]: true; } -export const CURRENT = Symbol('ember-resources::CURRENT'); +export const CURRENT = Symbol('ember-resources::CURRENT') as unknown as 'CURRENT'; export interface GlintRenderable { /** diff --git a/test-app/tests/core/issue-1128-test.gts b/test-app/tests/core/issue-1128-test.gts new file mode 100644 index 000000000..b56c592f8 --- /dev/null +++ b/test-app/tests/core/issue-1128-test.gts @@ -0,0 +1,72 @@ +import Component from '@glimmer/component'; +import { render } from '@ember/test-helpers'; +import { module, test } from 'qunit'; +import { setupRenderingTest } from 'ember-qunit'; + +import { cell, resource, use } from 'ember-resources'; + +import type { Reactive} from 'ember-resources'; + +type Cell = ReturnType>; + + export type ClockNakedSignature = { + percentage: Cell; + counter: Cell; +}; + +export type ClockSignature = Reactive; + +interface Signature { + Args: {}; + Blocks: { + default: [ClockNakedSignature]; + }; + Element: HTMLDivElement; +} + +const Clock = resource(() => { + const counter = cell(0); + const percentage = cell(0); + + return { percentage, counter }; +}); + + +// use (the function) exposes a .current property, like a Cell +class Refresher extends Component { + clock = use(this, Clock); + + +} + +// with use (the decorator) the .current access is absorbed in an underlying getter +class Refresher2 extends Component { + @use clock = Clock; + + +} + +const keys = (o: Record) => Object.keys(o).join(','); + +module('issues/1128', function(hooks) { + setupRenderingTest(hooks); + + test('it works', async function (assert) { + await render(); + + assert.dom('#one-keys').hasText('percentage,counter'); + assert.dom('#two-keys').hasText('percentage,counter'); + assert.dom('#one').hasText('0'); + assert.dom('#two').hasText('0'); + }); + +});