Skip to content

Commit

Permalink
Make types more consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Oct 11, 2024
1 parent 437d50d commit 81a90ce
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ember-resources/src/function-based/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export type ResourceFunction<Value = unknown> = (hooks: ResourceAPI) => Value |
* of the resource is the result of the collapsed functions
* passed to `resource`
*/
export type ResourceFn<Value = unknown> = (hooks: ResourceAPI) => Value;
export type ResourceFn<Value = unknown> = Value & ((hooks: ResourceAPI) => Value);

export type Destructor = () => void;
export type Cache = object;
1 change: 1 addition & 0 deletions test-app/app/components/implicit-current.gts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ export const Now = resource(({ on }) => {

<template>
It is: <time>{{Now}}</time>

It is: <time>{{Now.current}}</time>
</template>
38 changes: 38 additions & 0 deletions test-app/tests/core/implicit-current-test.gts
Original file line number Diff line number Diff line change
@@ -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(
<template>
<out id="implicit">{{Now}}</out>
<out id="explicit">{{Now.current}}</out>
</template>
);

assert.dom('#implicit').hasText('0');
assert.dom('explicit').hasText('0');

change();
await settled();

assert.dom('#implicit').hasText('1');
assert.dom('explicit').hasText('1');
});
});
4 changes: 4 additions & 0 deletions test-app/tests/type-tests/function-based.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { resource } from 'ember-resources';
import { expectTypeOf } from 'expect-type';
import { expectType } from 'ts-expect';

/*
Expand All @@ -13,3 +14,6 @@ import { expectType } from 'ts-expect';
*/
expectType<string>(resource(() => 'hi'));
expectType<string>(resource(() => () => 'hi'));

expectTypeOf(resource(() => 'hi')).toMatchTypeOf<string>();
expectTypeOf(resource(() => 'hi')).toMatchTypeOf<Resource<string>>();

0 comments on commit 81a90ce

Please sign in to comment.