Skip to content

Commit 2a9e233

Browse files
fix: update Binder class and bind function for improved type safety (#43)
* fix: update Binder class and bind function for improved type safety * Commit from GitHub Actions (CI) --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 715d91b commit 2a9e233

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

force-app/lwc/signals/core.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,16 @@ function $resource(fn, source, options) {
314314
error: null
315315
};
316316
} catch (error) {
317-
_signal.value = onError(error, _value, { identifier, initialValue }) ?? {
318-
data: null,
319-
loading: false,
320-
error
321-
};
317+
const errorValue = onError(error, _value, { identifier, initialValue });
318+
if (errorValue) {
319+
_signal.value = errorValue;
320+
} else {
321+
_signal.value = {
322+
data: null,
323+
loading: false,
324+
error
325+
};
326+
}
322327
} finally {
323328
_isInitialLoad = false;
324329
}

src/lwc/signals/core.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -599,10 +599,10 @@ function isSignal(anything: unknown): anything is Signal<unknown> {
599599
);
600600
}
601601

602-
class Binder {
602+
class Binder<Element extends HTMLElement> {
603603
constructor(
604-
private component: Record<string, object>,
605-
private propertyName: string
604+
private component: Element,
605+
private propertyName: keyof Element,
606606
) {}
607607

608608
to<T>(signal: Signal<T>) {
@@ -615,8 +615,8 @@ class Binder {
615615
}
616616
}
617617

618-
function bind(component: Record<string, object>, propertyName: string) {
619-
return new Binder(component, propertyName);
618+
function bind<T extends HTMLElement>(component: T, propertyName: keyof T) {
619+
return new Binder<T>(component, propertyName);
620620
}
621621

622622
export {
@@ -628,3 +628,4 @@ export {
628628
bind as $bind,
629629
isSignal
630630
};
631+

0 commit comments

Comments
 (0)