Open knownasilya opened 3 years ago
Dot-notation paths will be supported strongly-typed when https://github.com/sindresorhus/dot-prop/commit/09adad91e5a5072014b3380e769be8aae89738f2 is released and then used in conf
which this package depends on.
@sindresorhus Any specific reason that get
supports them now, but not delete
?
get
does not. It simply supports a string
.
Hum, this looks like it does, but I might
be mistaken.
@sindresorhus any thoughts?
I don't have time to look into that. This will be properly resolved at some point like I mentioned before. As a temporary workaround, a string
based overload could be added to .delete
too.
@knownasilya This is just typescript showing you the expanded types for the type case that match one of the 3 overloads.
🍊 is just your path... but it's a string
nothing else.
🔵 is your Store type... shown expanded.
I suspect that @sindresorhus is going to rely on some dark sorcery revolving around turning a JsonSchema into typescript types instead of relying on some type like :
// helper types
type Length<T> = T extends { length: infer L } ? L : never;
type PopFront<T extends unknown[]> = T extends [infer U, ...any] ? U : never;
type Shift<T extends unknown[]> = T extends [any, ...infer R] ? R : never;
type Filter<T extends unknown[], U> = T extends []
? []
: T extends [infer F, ...infer R]
? F extends U
? Filter<R, T>
: [F, ...Filter<R, U>]
: never;
type TupleIncludes<T extends unknown[], U> = Length<
Filter<T, U>
> extends Length<T>
? false
: true;
type StringIncludes<
S extends string,
D extends string
> = S extends `${string}${D}${string}` ? true : false;
type Includes<T extends unknown[] | string, U> = T extends unknown[]
? TupleIncludes<T, U>
: T extends string
? U extends string
? StringIncludes<T, U>
: never
: never;
type Join<T extends unknown[], D extends string> = PopFront<T> extends string
? Length<T> extends 1
? `${PopFront<T>}`
: Shift<T> extends string[]
? `${PopFront<T>}${D}${Join<Shift<T>, D>}`
: never
: never;
type Split<S extends string, D extends string> = string extends S
? string[]
: S extends ''
? []
: S extends `${infer T}${D}${infer U}`
? [T, ...Split<U, D>]
: [S];
// Create an object type from `ObjectType`, where the keys
// represent the keys of the `ObjectType` and the values
// represent the values of the `ObjectType`
export type NestedKeyOf<ObjectType extends object> = {
[Key in keyof ObjectType & (string | number)]: ObjectType[Key] extends object
? //@ts-ignore
Key | `${Key}.${NestedKeyOf<ObjectType[Key]>}`
: Key;
}[keyof ObjectType & (string | number)];
export type NestedType<T, P extends string> = Includes<P, '.'> extends true
? PopFront<Split<P, '.'>> extends keyof T
? NestedType<T[PopFront<Split<P, '.'>>], Join<Shift<Split<P, '.'>>, '.'>>
: never
: P extends keyof T
? T[P]
: never;
Which is naughty, because it ends up potentially breaking your computer due to inifinte recursion.
Sep 7, 2021, @sindresorhus
This will be properly resolved at some point like I mentioned before.
Since this bug is still open in late May, 2023, do you have a timeline on when this might happen?
late November 2023, still open
late September 2024, still open
I get this when I try to delete by key.