Skip to content

Commit

Permalink
Merge pull request #1019 from wagenet/fix-keep-latest-types
Browse files Browse the repository at this point in the history
Fix keepLatest types
  • Loading branch information
NullVoxPopuli authored Oct 20, 2023
2 parents 1c1ad1c + 11c4d62 commit 636e9ea
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
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
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>();

0 comments on commit 636e9ea

Please sign in to comment.