You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I've just come across this lib. Lots of great utilities.
I'm looking at AutoPath now - but all the examples I've seen so far are only showing it being used in context of a function argument.
I'm trying to see whether it can be used in a context of a generic type. Not sure if it's possible.
So, if I wanted a top-level-only fieldPath, the type would look like this:
export type Query<
T extends object = object,
K extends keyof T = keyof T> = [
fieldPath: K,
opStr: CompareOp,
value: T[K],
];
Thought that AutoPath might solve it for nested fields. But didn't manage to make it work for that case:
export type Query<
T extends object = object,
K extends string = string,
P extends AutoPath<T, K> = AutoPath<T, K>> = [
fieldPath: P,
opStr: CompareOp,
// value
];
I see that AutoPath is relying on second argument (P extends string) which seems to be getting inferred when used within a function. So, not sure if it can be used in such scenarios.
Trying to get TS to hint fields when creating an object of Query type and providing only T generic argument.
Is it possible to achieve that behaviour somehow?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi, I've just come across this lib. Lots of great utilities.
I'm looking at AutoPath now - but all the examples I've seen so far are only showing it being used in context of a function argument.
I'm trying to see whether it can be used in a context of a generic type. Not sure if it's possible.
So, if I wanted a top-level-only fieldPath, the type would look like this:
Thought that AutoPath might solve it for nested fields. But didn't manage to make it work for that case:
I see that
AutoPath
is relying on second argument (P extends string) which seems to be getting inferred when used within a function. So, not sure if it can be used in such scenarios.Trying to get TS to hint fields when creating an object of Query type and providing only T generic argument.
Is it possible to achieve that behaviour somehow?
Thank you
Beta Was this translation helpful? Give feedback.
All reactions