-
-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do I update a type on the fly using lodash.set? #225
Comments
Hey @nandorojo , that is because |
Is there a way to map a type from one to another, where certain fields are changed from number to Date?
|
Yes, I'll post the solution in a few minutes |
Sweet, I figure I can use that as the return type of my function |
Sorry, but I realized that the /* eslint-disable */
import type { S, F, O } from "ts-toolbelt";
declare function msToDates<O extends object, P extends string>(
obj: O,
paths: F.AutoPath<O, P>[]
): O.P.Update<O, S.Split<P, ".">, Date>;
const object = {
lastUpdated: 1616779693036,
createdAt: 1616779693019,
subProperty: {
milliseconds: 2123154541221
}
};
const objectWithDates = msToDates(object, [
"lastUpdated",
"subProperty.milliseconds"
]);
typeof objectWithDates.lastUpdated;
typeof objectWithDates.createdAt; I'm going to mark this issue as a bug, because I think most people will want the |
@millsp thanks so much for the details! |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
🍩 Feature Request
Is your feature request related to a problem?
I have a function that updates the type of an object. It turns milliseconds into date objects.
Here's the idea:
Describe the solution you'd like
A way to change the type of each field in the object, dynamically, based on the array of
paths
I pass.Describe alternatives you've considered
This is my code currently:
This works well. However, the
ReturnType
of thems
values I pass topaths
is still a number, not aDate
.Teachability, Documentation, Adoption, Migration Strategy
This might already be possible, curious if you have an idea how to do it @millsp. Thank you!
The text was updated successfully, but these errors were encountered: