Skip to content

Commit 80f666c

Browse files
committed
feat: Add NestedRecord type
1 parent 1feab08 commit 80f666c

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

.changeset/solid-lands-shine.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@layerstack/utils': patch
3+
---
4+
5+
feat: Add `NestedRecord` type

packages/utils/src/lib/typeHelpers.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
11
// https://basarat.gitbooks.io/typescript/docs/types/never.html#use-case-exhaustive-checks
22

3-
// import type { colors } from '../styles/theme.js';
4-
// import type { ComponentProps as SvelteComponentProps, SvelteComponent } from 'svelte';
5-
// import type { derived, Readable } from 'svelte/store';
6-
// import type {
7-
// FlyParams,
8-
// SlideParams,
9-
// BlurParams,
10-
// FadeParams,
11-
// ScaleParams,
12-
// } from 'svelte/transition';
13-
143
// https://www.typescriptlang.org/docs/handbook/basic-types.html#never
154
export function fail(message: string): never {
165
throw new Error(message);
@@ -28,9 +17,16 @@ export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
2817
*/
2918
export type Merge<M, N> = Omit<M, Extract<keyof M, keyof N>> & N;
3019

31-
// Get values of object (similar to Object.values())
20+
/**
21+
* Get values of object (similar to Object.values())
22+
*/
3223
export type ValueOf<T> = T[keyof T];
3324

25+
/**
26+
* Nested Record type
27+
*/
28+
export type NestedRecord<T> = { [key: string]: T | NestedRecord<T> };
29+
3430
// Get keys of object (strongly-typed)
3531
// Reason Object.keys() isn't like this by default due to runtime properties: https://github.com/Microsoft/TypeScript/pull/12253#issuecomment-263132208
3632
export function keys<T extends object>(o: T) {

0 commit comments

Comments
 (0)