-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: specify the behaviour of Get/Replace/Over when the needle is not…
… found — WIP #1
- Loading branch information
1 parent
26d0c7e
commit 6ce499c
Showing
6 changed files
with
89 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,29 @@ | ||
import { self, Param, Output, Key, PathItem, Indexable, Fn } from './types' | ||
import { Type, inferArgs } from 'free-types-core'; | ||
import { self, Param, Output, Key, PathItem, Fn } from './types' | ||
import { Type, inferArgs, Generic, apply } from 'free-types-core'; | ||
|
||
export { FollowPath } | ||
export { FollowPath, NOT_FOUND } | ||
|
||
declare const NOT_FOUND: unique symbol; | ||
type NOT_FOUND = typeof NOT_FOUND; | ||
|
||
type FollowPath<I extends PathItem, Data, Self> = | ||
I extends Output ? Data extends Fn ? ReturnType<Data> : never | ||
: I extends Param ? Data extends Fn ? Parameters<Data>[I['key']] : never | ||
: I extends Key ? Data extends Indexable ? Data[I] : never | ||
I extends Output ? Data extends Fn ? ReturnType<Data> : NOT_FOUND | ||
: I extends Param ? Data extends Fn ? Parameters<Data>[I['key']] : NOT_FOUND | ||
: I extends Key ? | ||
Data extends ReadonlyArray<unknown> | ||
? I extends keyof Data | ||
? Data[I] extends undefined ? NOT_FOUND : Data[I] | ||
: NOT_FOUND | ||
: Data extends Record<PropertyKey, unknown> | ||
? I extends keyof Data ? Data[I] : NOT_FOUND | ||
: NOT_FOUND | ||
: I extends self ? Self | ||
: I extends Type ? inferArgs<Data, I> : never | ||
: I extends Type ? FreeTypeArgs<Data, I> | ||
: NOT_FOUND | ||
|
||
type FreeTypeArgs<T, $T extends Type> = | ||
apply<$T, any[]> extends T | ||
? T extends Generic<$T> | ||
? inferArgs<T, $T> | ||
: NOT_FOUND | ||
: NOT_FOUND; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters