diff --git a/docs/globals.html b/docs/globals.html index d94fb5f..73cfbad 100644 --- a/docs/globals.html +++ b/docs/globals.html @@ -1698,7 +1698,7 @@

T

K1: keyof T

  • -

    K2: keyof T[K1]

    +

    K2: keyof U<T[K1]>

  • Parameters

    diff --git a/src/lib/get.ts b/src/lib/get.ts index 2e71c10..c56ec64 100644 --- a/src/lib/get.ts +++ b/src/lib/get.ts @@ -191,7 +191,7 @@ export function get( * @returns the nested value in the source. Value returned is the reference of the value in source. * Modifying this value will also modify the source value. */ -export function get( +export function get>( source: Optional, path: [K1, K2], ): U[K2] | undefined diff --git a/src/test/get.test.ts b/src/test/get.test.ts index 67c8d7a..729ac08 100644 --- a/src/test/get.test.ts +++ b/src/test/get.test.ts @@ -89,4 +89,13 @@ describe('get', () => { expect(get({ a: { b: false } }, ['a', 'b'], true)).toBe(false) expect(get({ a: { b: null } } as any, ['a', 'b'], true)).toBe(null) }) + + test('is working correctly for undefinable get with 2 elements', () => { + interface A { + [key: string]: { a: number } | undefined + } + + // the test is testing the typings of the get method + expect(get({} as A, ['k1', 'a'])).toBe(undefined) + }) })