Skip to content

Commit

Permalink
chore(list): more flexible keys
Browse files Browse the repository at this point in the history
  • Loading branch information
millsp committed Mar 6, 2021
1 parent 29eddd9 commit d9415b2
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion sources/List/AtLeast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {Keys} from '../Any/Keys'
* ```
*/
export type AtLeast<L extends List, K extends Key = Keys<L>> =
OAtLeast<ObjectOf<L>, `${K}` | K> extends infer U
OAtLeast<ObjectOf<L>, `${K & number}` | K> extends infer U
? U extends unknown // we distribute over the union
? _ListOf<U & {}> // each union member to a list
: never
Expand Down
2 changes: 1 addition & 1 deletion sources/List/Either.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {Boolean} from '../Boolean/_Internal'
* ```
*/
export type Either<L extends List, K extends Key, strict extends Boolean = 1> =
OEither<ObjectOf<L>, `${K}` | K, strict> extends infer OE
OEither<ObjectOf<L>, `${K & number}` | K, strict> extends infer OE
? OE extends unknown
? _ListOf<OE & {}>
: never
Expand Down
2 changes: 1 addition & 1 deletion sources/List/Has.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ import {List} from './List'
* ```
*/
export type Has<L extends List, K extends Key, M extends any = any, match extends Match = 'default'> =
OHas<ObjectOf<L>, `${K}` | K, M, match>
OHas<ObjectOf<L>, `${K & number}` | K, M, match>
2 changes: 1 addition & 1 deletion sources/List/NonNullable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ export type NonNullablePart<O extends object, K extends Key, depth extends Depth
* ```
*/
export type NonNullable<L extends List, K extends Key = Key, depth extends Depth = 'flat'> =
Cast<NonNullablePart<L, `${K}` | K, depth>, List>
Cast<NonNullablePart<L, `${K & number}` | K, depth>, List>
5 changes: 2 additions & 3 deletions sources/List/Nullable.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {Key} from './_Internal'
import {Depth} from '../Object/_Internal'
import {List} from './List'
import {Update} from '../Object/Update'
import {x} from '../Any/x'
Expand All @@ -15,5 +14,5 @@ import {Cast} from '../Any/Cast'
* ```ts
* ```
*/
export type Nullable<L extends List, K extends Key = Key, depth extends Depth = 'flat'> =
Cast<Update<L, `${K}` | K, x | null | undefined, depth>, List>
export type Nullable<L extends List, K extends Key = Key> =
Cast<Update<L, `${K & number}` | K, x | null | undefined>, List>
2 changes: 1 addition & 1 deletion sources/List/Omit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {ObjectOf} from './ObjectOf'
* @hidden
*/
export type _Omit<L extends List, K extends Key> =
_ListOf<_OOmit<ObjectOf<L>, `${K}` | K>>
_ListOf<_OOmit<ObjectOf<L>, `${K & number}` | K>>

/**
* Remove out of `L` the entries of key `K`
Expand Down
2 changes: 1 addition & 1 deletion sources/List/Pick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {List} from './List'
* @hidden
*/
export type _Pick<L extends List, K extends Key> =
_ListOf<_OPick<ObjectOf<L>, `${K}` | K>>
_ListOf<_OPick<ObjectOf<L>, `${K & number}` | K>>

/**
* Extract out of `L` the entries of key `K`
Expand Down
6 changes: 2 additions & 4 deletions sources/List/Undefinable.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {Key} from './_Internal'
import {Depth} from '../Object/_Internal'
import {List} from './List'
import {Update} from '../Object/Update'
import {x} from '../Any/x'
Expand All @@ -9,11 +8,10 @@ import {Cast} from '../Any/Cast'
* Make some entries of `L` not `undefined` (deeply or not)
* @param L to make non nullable
* @param K (?=`Key`) to choose fields
* @param depth (?=`'flat'`) 'deep' to do it deeply
* @returns [[List]]
* @example
* ```ts
* ```
*/
export type Undefinable<L extends List, K extends Key = Key, depth extends Depth = 'flat'> =
Cast<Update<L, `${K}` | K, x | undefined, depth>, List>
export type Undefinable<L extends List, K extends Key = Key> =
Cast<Update<L, `${K & number}` | K, x | undefined>, List>
5 changes: 2 additions & 3 deletions sources/List/Update.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {Key} from './_Internal'
import {List} from './List'
import {Update as OUpdate} from '../Object/Update'
import {Depth} from '../Object/_Internal'
import {Cast} from '../Any/Cast'

/**
Expand All @@ -15,5 +14,5 @@ import {Cast} from '../Any/Cast'
* ```ts
* ```
*/
export type Update<L extends List, K extends Key, A extends any, depth extends Depth = 'flat'> =
Cast<OUpdate<L, `${K}` | K | K, A, depth>, List>
export type Update<L extends List, K extends Key, A extends any> =
Cast<OUpdate<L, `${K & number}` | K, A>, List>
2 changes: 1 addition & 1 deletion sources/List/_Internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ import {List} from './List'
export type Naked<L extends List> =
Overwrite<Required<L>, L>

export type Key = string | number
export type Key = string | number | symbol

0 comments on commit d9415b2

Please sign in to comment.