Skip to content

Commit

Permalink
feat(types): [Values] construct tuple if T is string literal
Browse files Browse the repository at this point in the history
Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
  • Loading branch information
unicornware committed Aug 4, 2023
1 parent b85c3aa commit f0511fc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/types/__tests__/values.spec-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import type Person from '#fixtures/interfaces/person'
import type Vehicle from '#fixtures/types/vehicle'
import type EmptyArray from '../empty-array'
import type EmptyObject from '../empty-object'
import type EmptyString from '../empty-string'
import type Fn from '../fn'
import type Get from '../get'
import type Nullable from '../nullable'
import type OmitNative from '../omit-native'
import type Opaque from '../opaque'
import type { tag as opaque } from '../opaque'
import type Partial from '../partial'
import type Split from '../split'
import type Spread from '../spread'
import type TestSubject from '../values'
import type Writable from '../writable'
Expand Down Expand Up @@ -125,13 +127,12 @@ describe('unit-d:types/Values', () => {

describe('T extends string', () => {
describe('IsLiteral<T> extends true', () => {
it('should equal Get<OmitNative<Spread<T>, symbol>, any>[]', () => {
it('should equal Split<T, EmptyString>', () => {
// Arrange
type T = 'vin'
type Expect = Get<OmitNative<Spread<T>, symbol>, any>[]

// Expect
expectTypeOf<TestSubject<T>>().toEqualTypeOf<Expect>()
expectTypeOf<TestSubject<T>>().toEqualTypeOf<Split<T, EmptyString>>()
})
})

Expand Down
3 changes: 3 additions & 0 deletions src/types/values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type Get from './get'
import type IfNumeric from './if-numeric'
import type IfSymbol from './if-symbol'
import type IsAny from './is-any'
import type IsLiteral from './is-literal'
import type IsNever from './is-never'
import type IsTuple from './is-tuple'
import type Spread from './spread'
Expand Down Expand Up @@ -61,6 +62,8 @@ type Values<T> = IsAny<T> extends true
? EmptyArray
: T extends readonly never[]
? EmptyArray
: IsLiteral<T, string> extends true
? TupleFromRecord<{ [K in keyof U as UnwrapNumeric<K>]: U[K] }>
: IsTuple<T> extends true
? TupleFromRecord<{
[K in keyof U as UnwrapNumeric<K>]: U[K]
Expand Down

0 comments on commit f0511fc

Please sign in to comment.