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 keepLatest types #1019

Merged
merged 4 commits into from
Oct 20, 2023
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
9 changes: 9 additions & 0 deletions .changeset/sour-coats-shop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"ember-resources": patch
---

The `keepLatest` utility previously incorrectly had a `| undefined` type for the return value.
That's been removed.

`| undefined` is still a valid type if the passed value is possibly `| undefined`.
This made the `| undefined` on `keepLatest` redundant.
2 changes: 1 addition & 1 deletion ember-resources/src/util/keep-latest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ interface Options<T = unknown> {
*/
export function keepLatest<Return = unknown>({ when, value: valueFn }: Options<Return>) {
return resource(() => {
let previous: Return | undefined;
let previous: Return;

return () => {
let value = valueFn();
Expand Down
12 changes: 12 additions & 0 deletions ember-resources/type-tests/keep-latest.test.ts
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the type tests!

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { expectTypeOf } from 'expect-type';

import { keepLatest } from '../src/util/keep-latest';

const foo: boolean = true;

const value = keepLatest({
value: () => foo,
when: () => true,
});

expectTypeOf(value).toMatchTypeOf<boolean>();
Loading