Skip to content

Commit bae9f18

Browse files
fix(signals): do not create deep signals for empty objects and unknown records with symbol keys (#4880)
1 parent 9fefc77 commit bae9f18

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,14 @@ describe('signalState', () => {
298298
});
299299
const bar = state5.bar;
300300
const baz = bar.baz;
301+
302+
const state6 = signalState({
303+
x: {} as Record<symbol, string>
304+
});
305+
const x = state6.x;
306+
307+
const state7 = signalState({ y: {} });
308+
const y = state7.y;
301309
`;
302310

303311
expectSnippet(snippet).toSucceed();
@@ -353,6 +361,17 @@ describe('signalState', () => {
353361
);
354362

355363
expectSnippet(snippet).toInfer('baz', 'Signal<Record<number, unknown>>');
364+
365+
expectSnippet(snippet).toInfer(
366+
'state6',
367+
'SignalState<{ x: Record<symbol, string>; }>'
368+
);
369+
370+
expectSnippet(snippet).toInfer('x', 'Signal<Record<symbol, string>>');
371+
372+
expectSnippet(snippet).toInfer('state7', 'SignalState<{ y: {}; }>');
373+
374+
expectSnippet(snippet).toInfer('y', 'Signal<{}>');
356375
});
357376

358377
it('succeeds when state is an empty object', () => {

modules/signals/src/ts-helpers.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ export type IsRecord<T> = T extends object
1818
: true
1919
: false;
2020

21-
export type IsUnknownRecord<T> = string extends keyof T
21+
export type IsUnknownRecord<T> = keyof T extends never
22+
? true
23+
: string extends keyof T
24+
? true
25+
: symbol extends keyof T
2226
? true
2327
: number extends keyof T
2428
? true

0 commit comments

Comments
 (0)