From 8e388ed2a779b652a359b8e5b19c3656c1d34b88 Mon Sep 17 00:00:00 2001 From: Peter Wagenet Date: Thu, 19 Oct 2023 10:45:45 -0700 Subject: [PATCH 1/4] Fix keepLatest types --- ember-resources/src/util/keep-latest.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ember-resources/src/util/keep-latest.ts b/ember-resources/src/util/keep-latest.ts index 97f226d73..c46224b99 100644 --- a/ember-resources/src/util/keep-latest.ts +++ b/ember-resources/src/util/keep-latest.ts @@ -69,7 +69,7 @@ interface Options { */ export function keepLatest({ when, value: valueFn }: Options) { return resource(() => { - let previous: Return | undefined; + let previous: Return; return () => { let value = valueFn(); From 40469f06f1d1e1bef3e962b975d510629d45ac88 Mon Sep 17 00:00:00 2001 From: Peter Wagenet Date: Thu, 19 Oct 2023 11:14:54 -0700 Subject: [PATCH 2/4] Add type test --- ember-resources/type-tests/keep-latest.test.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 ember-resources/type-tests/keep-latest.test.ts diff --git a/ember-resources/type-tests/keep-latest.test.ts b/ember-resources/type-tests/keep-latest.test.ts new file mode 100644 index 000000000..219fa8e1e --- /dev/null +++ b/ember-resources/type-tests/keep-latest.test.ts @@ -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(); From d63d7b7d72702babc195fe70142741d3d083e290 Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Thu, 19 Oct 2023 22:43:00 -0600 Subject: [PATCH 3/4] Add changeset --- .changeset/sour-coats-shop.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .changeset/sour-coats-shop.md diff --git a/.changeset/sour-coats-shop.md b/.changeset/sour-coats-shop.md new file mode 100644 index 000000000..4e6325e35 --- /dev/null +++ b/.changeset/sour-coats-shop.md @@ -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. From 11c4d6277fb70c1e3b105245c054df32e508d733 Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Thu, 19 Oct 2023 22:50:17 -0600 Subject: [PATCH 4/4] lint:fix --- ember-resources/type-tests/keep-latest.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ember-resources/type-tests/keep-latest.test.ts b/ember-resources/type-tests/keep-latest.test.ts index 219fa8e1e..9c6d34883 100644 --- a/ember-resources/type-tests/keep-latest.test.ts +++ b/ember-resources/type-tests/keep-latest.test.ts @@ -6,7 +6,7 @@ const foo: boolean = true; const value = keepLatest({ value: () => foo, - when: () => true + when: () => true, }); expectTypeOf(value).toMatchTypeOf();