Open
Description
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the issue has not already been raised
Issue
Currently Query's do not have dotted path suggestions, but would be possible with current typescript.
TL;DR:
a simple example of what the stackoverflow answer has does (note: the types are directly copied from the answer)
interface Test {
somenested?: {
path: string;
};
somethingelse?: string;
}
type PathsToStringProps<T> = T extends string
? []
: {
[K in Extract<keyof T, string>]: [K, ...PathsToStringProps<T[K]>];
}[Extract<keyof T, string>];
type Join<T extends string[], D extends string> = T extends []
? never
: T extends [infer F]
? F
: T extends [infer F, ...infer R]
? F extends string
? `${F}${D}${Join<Extract<R, string[]>, D>}`
: never
: string;
function onlyDotted(input: Join<PathsToStringProps<Test>, '.'>) {
console.log('input', input);
}
onlyDotted('somenested.path'); // works, with suggestions
onlyDotted('somethingelse'); // also works, with suggestions
onlyDotted('ERROR'); // error, property does not exist
Disclaimer: i am by no means a expert at complex typescript types, i also have no clue about the effect on types performance this would bring