fix: reconcile flight aircraft/airline types with form input#674
Closed
mhlas7 wants to merge 1 commit into
Closed
Conversation
…g type conflict errors
Contributor
|
Label error. Requires exactly 1 of: changelog:.*. Found: Web |
|
Owner
|
Thanks, went ahead and fixed all the type errors in the app instead though, including this one. Honestly the main reason I never did it previously was because |
Contributor
Author
|
I got svelte-check running but I had to manually set the memory heap to 10 Gb of RAM otherwise it would OOM. Glad these are all fixed! |
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.



Error
When saving a flight, the save util (
src/lib/server/utils/flight.ts) builds avaluesobject from form data and passes it as aCreateFlight. TypeScript rejected that at bothsaveFlightValues(values)call sites (the partial-date and day-precision branches). The error:The issue behind it
CreateFlighttyped itsaircraft/airlineas the full DB records (Aircraft = Selectable<aircraft>,Airline = Selectable<airline>), which require a non-nullidand asourceId. But the flight form produces looser objects (fromaircraftSchema/airlineSchema):idisnumber | null— a not-yet-created aircraft/airline has a null idaircraftSchemahas nosourceId(andairlineSchema'ssourceId/iconPathare optional)The error message only names
sourceIdbecause TypeScript reports the first incompatible property, but there are really two gaps — the missingsourceIdand theid: number | null → numbermismatch — affecting both aircraft and airline.Key facts that shaped the fix:
idnon-null), because they're shared with theaircraft/airline create forms where a null id is valid.
.idis ever read off these fields (src/lib/db/queries.ts—aircraftId/airlineId); nothing usesname/icao/sourceId.null, so they still satisfy a loosened type.The fix (
src/lib/db/types.ts)Loosen the two
CreateFlightfields to "anAircraft/Airline, but with a nullable id and without the fields the form omits" — derived from the DB types soname/icao/iatastay in sync:Both the form's schema outputs and full
Aircraft/Airlinerecords assign to these, and.idstill types asnumber | null— a types-only change with no runtime behavior difference. (Airline also dropsiconPathbecauseOmit<Airline, 'id' | 'sourceId'>would otherwise keep it required, while the form has it optional.)Verified: the
TS2345 … not assignable to 'CreateFlight'errors inflight.tsand the importers are gone; prettier clean. Single-file change onfix/aircraft-airline-createflight-type(off currentorigin/main).Note
Fix aircraft and airline types in
CreateFlightto accept nullable IDs for unsaved entitiesIntroduces
FlightAircraftInputandFlightAirlineInputtype aliases in types.ts to represent aircraft and airline data as it arrives from form input. Both types omit fields not present in form input (e.g.sourceId,iconPath) and reintroduceidas nullable to handle not-yet-persisted entities. TheCreateFlighttype is updated to use these input-focused types instead of the fullAircraftandAirlinetypes.Macroscope summarized 71b7523.