Skip to content

Commit 4a4a5db

Browse files
fix(signals): remove internal Signal type (#4867)
1 parent 551ceb4 commit 4a4a5db

File tree

3 files changed

+42
-33
lines changed

3 files changed

+42
-33
lines changed

modules/signals/spec/types/signal-state.types.spec.ts

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -121,90 +121,117 @@ describe('signalState', () => {
121121
it('does not create deep signals for iterables', () => {
122122
const snippet = `
123123
const arrayState = signalState<string[]>([]);
124+
const arrayStateValue = arrayState();
124125
declare const arrayStateKeys: keyof typeof arrayState;
125126
126127
const setState = signalState(new Set<number>());
128+
const setStateValue = setState();
127129
declare const setStateKeys: keyof typeof setState;
128130
129131
const mapState = signalState(new Map<number, { bar: boolean }>());
132+
const mapStateValue = mapState();
130133
declare const mapStateKeys: keyof typeof mapState;
131134
132135
const uintArrayState = signalState(new Uint8ClampedArray());
136+
const uintArrayStateValue = uintArrayState();
133137
declare const uintArrayStateKeys: keyof typeof uintArrayState;
134138
`;
135139

136140
expectSnippet(snippet).toSucceed();
137141

142+
expectSnippet(snippet).toInfer('arrayStateValue', 'string[]');
138143
expectSnippet(snippet).toInfer(
139144
'arrayStateKeys',
140-
'unique symbol | keyof Signal<string[]>'
145+
'unique symbol | unique symbol'
141146
);
142147

148+
expectSnippet(snippet).toInfer('setStateValue', 'StateResult<Set<number>>');
143149
expectSnippet(snippet).toInfer(
144150
'setStateKeys',
145-
'unique symbol | keyof Signal<StateResult<Set<number>>>'
151+
'unique symbol | unique symbol'
146152
);
147153

154+
expectSnippet(snippet).toInfer(
155+
'mapStateValue',
156+
'StateResult<Map<number, { bar: boolean; }>>'
157+
);
148158
expectSnippet(snippet).toInfer(
149159
'mapStateKeys',
150-
'unique symbol | keyof Signal<StateResult<Map<number, { bar: boolean; }>>>'
160+
'unique symbol | unique symbol'
151161
);
152162

163+
expectSnippet(snippet).toInfer(
164+
'uintArrayStateValue',
165+
'StateResult<Uint8ClampedArray<ArrayBuffer>>'
166+
);
153167
expectSnippet(snippet).toInfer(
154168
'uintArrayStateKeys',
155-
'unique symbol | keyof Signal<StateResult<Uint8ClampedArray<ArrayBuffer>>>'
169+
'unique symbol | unique symbol'
156170
);
157171
});
158172

159173
it('does not create deep signals for built-in object types', () => {
160174
const snippet = `
161175
const weakSetState = signalState(new WeakSet<{ foo: string }>());
176+
const weakSetStateValue = weakSetState();
162177
declare const weakSetStateKeys: keyof typeof weakSetState;
163178
164179
const dateState = signalState(new Date());
180+
const dateStateValue = dateState();
165181
declare const dateStateKeys: keyof typeof dateState;
166182
167183
const errorState = signalState(new Error());
184+
const errorStateValue = errorState();
168185
declare const errorStateKeys: keyof typeof errorState;
169186
170187
const regExpState = signalState(new RegExp(''));
188+
const regExpStateValue = regExpState();
171189
declare const regExpStateKeys: keyof typeof regExpState;
172190
`;
173191

174192
expectSnippet(snippet).toSucceed();
175193

194+
expectSnippet(snippet).toInfer(
195+
'weakSetStateValue',
196+
'StateResult<WeakSet<{ foo: string; }>>'
197+
);
176198
expectSnippet(snippet).toInfer(
177199
'weakSetStateKeys',
178-
'unique symbol | keyof Signal<StateResult<WeakSet<{ foo: string; }>>>'
200+
'unique symbol | unique symbol'
179201
);
180202

203+
expectSnippet(snippet).toInfer('dateStateValue', 'StateResult<Date>');
181204
expectSnippet(snippet).toInfer(
182205
'dateStateKeys',
183-
'unique symbol | keyof Signal<StateResult<Date>>'
206+
'unique symbol | unique symbol'
184207
);
185208

209+
expectSnippet(snippet).toInfer('errorStateValue', 'StateResult<Error>');
186210
expectSnippet(snippet).toInfer(
187211
'errorStateKeys',
188-
'unique symbol | keyof Signal<StateResult<Error>>'
212+
'unique symbol | unique symbol'
189213
);
190214

215+
expectSnippet(snippet).toInfer('regExpStateValue', 'StateResult<RegExp>');
191216
expectSnippet(snippet).toInfer(
192217
'regExpStateKeys',
193-
'unique symbol | keyof Signal<StateResult<RegExp>>'
218+
'unique symbol | unique symbol'
194219
);
195220
});
196221

197222
it('does not create deep signals for functions', () => {
198223
const snippet = `
199224
const state = signalState(() => {});
225+
const stateValue = state();
200226
declare const stateKeys: keyof typeof state;
201227
`;
202228

203229
expectSnippet(snippet).toSucceed();
204230

231+
expectSnippet(snippet).toInfer('stateValue', 'StateResult<() => void>');
205232
expectSnippet(snippet).toInfer(
206233
'stateKeys',
207-
'unique symbol | keyof Signal<StateResult<() => void>>'
234+
'unique symbol | unique symbol'
208235
);
209236
});
210237

@@ -282,7 +309,7 @@ describe('signalState', () => {
282309

283310
expectSnippet(snippet).toInfer(
284311
'state1Keys',
285-
'unique symbol | keyof Signal<StateResult<{ [key: string]: number; }>>'
312+
'unique symbol | unique symbol'
286313
);
287314

288315
expectSnippet(snippet).toInfer(
@@ -292,7 +319,7 @@ describe('signalState', () => {
292319

293320
expectSnippet(snippet).toInfer(
294321
'state2Keys',
295-
'unique symbol | keyof Signal<StateResult<{ [key: number]: { foo: string; }; }>>'
322+
'unique symbol | unique symbol'
296323
);
297324

298325
expectSnippet(snippet).toInfer(
@@ -302,7 +329,7 @@ describe('signalState', () => {
302329

303330
expectSnippet(snippet).toInfer(
304331
'state3Keys',
305-
'unique symbol | keyof Signal<StateResult<Record<string, { bar: number; }>>>'
332+
'unique symbol | unique symbol'
306333
);
307334

308335
expectSnippet(snippet).toInfer(
@@ -398,10 +425,7 @@ describe('signalState', () => {
398425
expectSnippet(snippet).toSucceed();
399426
expectSnippet(snippet).toInfer('name', 'Signal<number>');
400427
expectSnippet(snippet).toInfer('length1', 'Signal<boolean[]>');
401-
expectSnippet(snippet).toInfer(
402-
'name2',
403-
'Signal<{ length: string; }> & Readonly<{ length: Signal<string>; }>'
404-
);
428+
expectSnippet(snippet).toInfer('name2', 'DeepSignal<{ length: string; }>');
405429
expectSnippet(snippet).toInfer('length2', 'Signal<string>');
406430
});
407431

modules/signals/spec/types/signal-store.types.spec.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,7 @@ describe('signalStore', () => {
366366
`;
367367

368368
expectSnippet(snippet2).toSucceed();
369-
expectSnippet(snippet2).toInfer(
370-
'length',
371-
'Signal<{ name: boolean; }> & Readonly<{ name: Signal<boolean>; }>'
372-
);
369+
expectSnippet(snippet2).toInfer('length', 'DeepSignal<{ name: boolean; }>');
373370
expectSnippet(snippet2).toInfer('name', 'Signal<boolean>');
374371
});
375372

modules/signals/src/deep-signal.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
import {
2-
computed,
3-
isSignal,
4-
Signal as NgSignal,
5-
untracked,
6-
} from '@angular/core';
1+
import { computed, isSignal, Signal, untracked } from '@angular/core';
72
import { IsKnownRecord } from './ts-helpers';
83

9-
// An extended Signal type that enables the correct typing
10-
// of nested signals with the `name` or `length` key.
11-
export interface Signal<T> extends NgSignal<T> {
12-
name: unknown;
13-
length: unknown;
14-
}
15-
164
const DEEP_SIGNAL = Symbol('DEEP_SIGNAL');
175

186
export type DeepSignal<T> = Signal<T> &

0 commit comments

Comments
 (0)