fix: type fieldUpdatedAt/fieldCreatedAt as Date in CRUD callbacks#648
Closed
MMMikeM wants to merge 2 commits into
Closed
fix: type fieldUpdatedAt/fieldCreatedAt as Date in CRUD callbacks#648MMMikeM wants to merge 2 commits into
MMMikeM wants to merge 2 commits into
Conversation
These tests document the current type mismatch: clone() converts ISO 8601 strings to Date at runtime, but the callback parameter types still say string. The expectTypeOf assertions expect Date, so these tests will show type errors until the types are fixed.
clone() uses a JSON reviver that converts ISO 8601 strings to Date objects at runtime. The create/update/delete callback parameter types now reflect this when fieldUpdatedAt or fieldCreatedAt is specified. When neither field is set, types are unchanged (backwards compatible).
38aaef2 to
11f7b4d
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
clone()uses a JSON reviver that converts ISO 8601 strings toDateobjects at runtime. WhenfieldUpdatedAtorfieldCreatedAtis specified insyncedCrud, thecreate/update/deletecallback parameters receiveDatevalues for those fields — but the TypeScript types still saystring.This PR makes the types honest by:
FUpdatedAt/FCreatedAtstring literal type params toSyncedCrudPropsBaseand allsyncedCrudoverloadsCrudCallbackInpututility type that remaps the specified field keys fromstringtoDateBefore
After
Caveat
TypeScript doesn't support partial type argument inference. If the user explicitly specifies
TRemote(e.g.syncedCrud<Task>({...})),FUpdatedAt/FCreatedAtfall back toundefinedand the date fields stay typed asstring. This only affects the explicit-generic case — the common pattern of lettingTRemotebe inferred fromlist/getworks correctly.Test plan
fieldUpdatedAtandfieldCreatedAtset: date fields typed asDate, others unchangedfieldUpdatedAt: only that field becomesDate,fieldCreatedAtstaysstring