Skip to content

Commit

Permalink
feat: add support for numeric objects
Browse files Browse the repository at this point in the history
  • Loading branch information
allohamora committed Sep 12, 2023
1 parent c751701 commit d44c80a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions __tests__/unit/config.manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('ConfigManager', () => {
getConfig: () => ({
root: { sub: { inner: 1, arr: [1, 2, 3] } },
root2: { empty: undefined, nullable: null },
root3: { [0]: 123 },
false: false,
emptyString: '',
notPlain,
Expand Down Expand Up @@ -45,6 +46,14 @@ describe('ConfigManager', () => {
expect(manager.getOrThrow('root2')).toEqual({ empty: undefined, nullable: null });
});

it('returns root3', () => {
expect(manager.getOrThrow('root3')).toEqual({ [0]: 123 });
});

it('returns root3.0', () => {
expect(manager.getOrThrow('root3.0')).toEqual(123);
});

it('returns false', () => {
expect(manager.getOrThrow('false')).toBe(false);
});
Expand Down
2 changes: 1 addition & 1 deletion src/utils/flatten.utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
type SupportedValues = bigint | boolean | null | number | string | symbol | undefined | object;

// original https://github.com/ghoullier/awesome-template-literal-types#dot-notation-string-type-safe
export type PathImpl<Obj, Key extends keyof Obj> = Key extends string
export type PathImpl<Obj, Key extends keyof Obj> = Key extends string | number
? Obj[Key] extends Record<string, SupportedValues>
? Key | `${Key}.${PathImpl<Obj[Key], keyof Obj[Key]>}`
: Key
Expand Down

0 comments on commit d44c80a

Please # to comment.