Skip to content

Commit 1eaf920

Browse files
JoostKmattrbeck
authored andcommitted
refactor(core): declare explicit reactive node prototypes types
These type annotations allow TS to associate the object's properties with their corresponding declaration in the interfaces, enabling much better code navigation. For example, "Find all implementations" for `ReactiveNode.producerRecomputeValue` now finds the implementation in `COMPUTED_NODE` and `LINKED_SIGNAL_NODE`.
1 parent 523d69a commit 1eaf920

4 files changed

Lines changed: 10 additions & 4 deletions

File tree

packages/core/primitives/signals/src/computed.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export const ERRORED: any = /* @__PURE__ */ Symbol('ERRORED');
114114

115115
// Note: Using an IIFE here to ensure that the spread assignment is not considered
116116
// a side-effect, ending up preserving `COMPUTED_NODE` and `REACTIVE_NODE`.
117-
const COMPUTED_NODE = /* @__PURE__ */ (() => {
117+
const COMPUTED_NODE: Omit<ComputedNode<unknown>, 'computation'> = /* @__PURE__ */ (() => {
118118
return {
119119
...REACTIVE_NODE,
120120
value: UNSET,

packages/core/primitives/signals/src/linked_signal.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@ export function linkedSignalUpdateFn<S, D>(
124124

125125
// Note: Using an IIFE here to ensure that the spread assignment is not considered
126126
// a side-effect, ending up preserving `LINKED_SIGNAL_NODE` and `REACTIVE_NODE`.
127-
export const LINKED_SIGNAL_NODE: object = /* @__PURE__ */ (() => {
127+
export const LINKED_SIGNAL_NODE: Omit<
128+
LinkedSignalNode<unknown, unknown>,
129+
'computation' | 'source' | 'sourceValue'
130+
> = /* @__PURE__ */ (() => {
128131
return {
129132
...REACTIVE_NODE,
130133
value: UNSET,

packages/core/primitives/signals/src/watch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ const NOOP_CLEANUP_FN: WatchCleanupFn = () => {};
140140

141141
// Note: Using an IIFE here to ensure that the spread assignment is not considered
142142
// a side-effect, ending up preserving `COMPUTED_NODE` and `REACTIVE_NODE`.
143-
const WATCH_NODE: Partial<WatchNode> = /* @__PURE__ */ (() => {
143+
const WATCH_NODE: Omit<WatchNode, 'fn' | 'schedule' | 'ref'> = /* @__PURE__ */ (() => {
144144
return {
145145
...REACTIVE_NODE,
146146
consumerIsAlwaysLive: true,

packages/core/src/render3/reactivity/after_render_effect.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ export interface AfterRenderPhaseEffectNode extends SignalNode<unknown> {
7777
phaseFn(previousValue?: unknown): unknown;
7878
}
7979

80-
const AFTER_RENDER_PHASE_EFFECT_NODE = /* @__PURE__ */ (() => ({
80+
const AFTER_RENDER_PHASE_EFFECT_NODE: Omit<
81+
AfterRenderPhaseEffectNode,
82+
'phase' | 'sequence' | 'userFn' | 'signal' | 'registerCleanupFn'
83+
> = /* @__PURE__ */ (() => ({
8184
...SIGNAL_NODE,
8285
kind: 'afterRenderEffectPhase',
8386
consumerIsAlwaysLive: true,

0 commit comments

Comments
 (0)