From 0c1f420739904d536e55caa12688527dae9d9c9c Mon Sep 17 00:00:00 2001 From: Lexus Drumgold Date: Fri, 12 May 2023 01:35:39 -0400 Subject: [PATCH] refactor(types)!: `KeysRequired` -> `RequiredKeys` Signed-off-by: Lexus Drumgold --- src/types/__tests__/keys-required.spec-d.ts | 6 +++--- src/types/index.ts | 2 +- src/types/keys-required.ts | 12 +++++++----- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/types/__tests__/keys-required.spec-d.ts b/src/types/__tests__/keys-required.spec-d.ts index 7ae93efc..31371d50 100644 --- a/src/types/__tests__/keys-required.spec-d.ts +++ b/src/types/__tests__/keys-required.spec-d.ts @@ -1,11 +1,11 @@ /** - * @file Type Tests - KeysRequired - * @module tutils/types/tests/unit-d/KeysRequired + * @file Type Tests - RequiredKeys + * @module tutils/types/tests/unit-d/RequiredKeys */ import type TestSubject from '../keys-required' -describe('unit-d:types/KeysRequired', () => { +describe('unit-d:types/RequiredKeys', () => { it('should extract required keys from T', () => { // Arrange type T = { display_name?: string; username: string } diff --git a/src/types/index.ts b/src/types/index.ts index 963e39c1..86a812bf 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -30,7 +30,7 @@ export type { default as JsonifiableArray } from './jsonifiable-array' export type { default as JsonifiableInstance } from './jsonifiable-instance' export type { default as JsonifiableObject } from './jsonifiable-object' export type { default as OptionalKeys } from './keys-optional' -export type { default as KeysRequired } from './keys-required' +export type { default as RequiredKeys } from './keys-required' export type { default as LiteralUnion } from './literal-union' export type { default as NIL } from './nil' export type { default as Nilable } from './nilable' diff --git a/src/types/keys-required.ts b/src/types/keys-required.ts index 04034d8a..3a97cb30 100644 --- a/src/types/keys-required.ts +++ b/src/types/keys-required.ts @@ -1,6 +1,6 @@ /** - * @file Type Definitions - KeysRequired - * @module tutils/types/KeysRequired + * @file Type Definitions - RequiredKeys + * @module tutils/types/RequiredKeys */ import type ObjectPlain from './object-plain' @@ -8,11 +8,13 @@ import type ObjectPlain from './object-plain' /** * Extracts all required keys from `T`. * - * @template T - Object type + * @todo support nested keys + * + * @template T - Object type to evaluate */ -type KeysRequired = Exclude< +type RequiredKeys = Exclude< { [K in keyof T]: T extends Record ? K : never }[keyof T], undefined > -export type { KeysRequired as default } +export type { RequiredKeys as default }