Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(types): useResource types now reflect that you *can* make non-rea… #168

Merged
merged 1 commit into from
Sep 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions addon/-private/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ export interface Helper {
}

export type Thunk =
// No Args
| (() => [])
| (() => void)
// plain array / positional args
| (() => Required<ArgsWrapper>['positional'])
// plain named args
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion tests/unit/types-test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-console */
/* eslint-disable @typescript-eslint/no-explicit-any */
import { LifecycleResource, Resource } from 'ember-resources';
import { LifecycleResource, Resource, useResource } from 'ember-resources';

import type { Named } from 'ember-resources';

Expand All @@ -22,3 +22,14 @@ export function Issue108TypeTest() {

return issue108p2a.args.named?.foo;
}

// https://github.com/NullVoxPopuli/ember-resources/issues/48
export function Issue48TypeTest(): unknown {
class TestResource extends Resource {}

return class TestCaseComponent {
test = useResource(this, TestResource, () => {});
testArray = useResource(this, TestResource, () => []);
testVoid = useResource(this, TestResource);
};
}
18 changes: 18 additions & 0 deletions tests/unit/use-resource-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,24 @@ module('useResource', function () {
});
});

test('does not need args', async function (assert) {
class TestResource extends Resource {
foo = 3;
}

class Test {
dataArray = useResource(this, TestResource, () => []);
dataVoid = useResource(this, TestResource, () => {});
dataOmitted = useResource(this, TestResource);
}

let foo = new Test();

assert.equal(foo.dataArray.foo, 3);
assert.equal(foo.dataVoid.foo, 3);
assert.equal(foo.dataOmitted.foo, 3);
});

module('in templates', function (hooks) {
setupRenderingTest(hooks);

Expand Down