Skip to content

Commit

Permalink
Remove unnecessary overload from createSelector
Browse files Browse the repository at this point in the history
  • Loading branch information
thetarnav committed Jun 5, 2023
1 parent a7270bc commit fcf55d1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .changeset/five-cats-compare.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"solid-js": patch
---

Add function overloads to `createSelector` to improve type inference.
Improve type inference of `createSelector`.
6 changes: 0 additions & 6 deletions packages/solid/src/reactive/signal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -784,13 +784,7 @@ export type EqualityCheckerFunction<T, U> = (a: U, b: T) => boolean;
*
* @description https://www.solidjs.com/docs/latest/api#createselector
*/
export function createSelector<T, U = T>(source: Accessor<T>): (key: U) => boolean;
export function createSelector<T, U = T>(
source: Accessor<T>,
fn: EqualityCheckerFunction<T, U>,
options?: BaseOptions
): (key: U) => boolean;
export function createSelector<T, U>(
source: Accessor<T>,
fn: EqualityCheckerFunction<T, U> = equalFn as TODO,
options?: BaseOptions
Expand Down
16 changes: 16 additions & 0 deletions packages/solid/test/signals.type-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,12 @@ const onMemo4: Accessor<number> = onMemo3;
// @ts-expect-error Argument of type 'string' is not assignable to parameter of type 'number'. ts(2345)
const bool2: boolean = selector("123");
}
{
const selector = createSelector(() => 123, undefined, { name: "test" });
const bool: boolean = selector(123);
// @ts-expect-error Argument of type 'string' is not assignable to parameter of type 'number'. ts(2345)
const bool2: boolean = selector("123");
}
{
const selector = createSelector<number | string>(() => 123);
const bool: boolean = selector(123);
Expand All @@ -746,6 +752,16 @@ const onMemo4: Accessor<number> = onMemo3;
const bool: boolean = selector(123);
const bool2: boolean = selector("123");
}
{
const selector = createSelector(
() => 123,
(key, source) => key === source,
{ name: "test" }
);
const bool: boolean = selector(123);
// @ts-expect-error Argument of type 'string' is not assignable to parameter of type 'number'. ts(2345)
const bool2: boolean = selector("123");
}

//////////////////////////////////////////////////////////////////////////
// variations of signal types ////////////////////////////////////////////
Expand Down

0 comments on commit fcf55d1

Please sign in to comment.