Skip to content

Commit

Permalink
refactor(types)!: KeysRequired -> RequiredKeys
Browse files Browse the repository at this point in the history
Signed-off-by: Lexus Drumgold <[email protected]>
  • Loading branch information
unicornware committed May 12, 2023
1 parent 512272d commit 0c1f420
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/types/__tests__/keys-required.spec-d.ts
Original file line number Diff line number Diff line change
@@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
12 changes: 7 additions & 5 deletions src/types/keys-required.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
/**
* @file Type Definitions - KeysRequired
* @module tutils/types/KeysRequired
* @file Type Definitions - RequiredKeys
* @module tutils/types/RequiredKeys
*/

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<T extends ObjectPlain> = Exclude<
type RequiredKeys<T extends ObjectPlain> = Exclude<
{ [K in keyof T]: T extends Record<K, T[K]> ? K : never }[keyof T],
undefined
>

export type { KeysRequired as default }
export type { RequiredKeys as default }

0 comments on commit 0c1f420

Please sign in to comment.