Repository navigation
Conversation
`deserialize<T = unknown>(document: unknown): T` accepts anything, so a caller can annotate its API call with the *deserialized* type, pass it in, and nothing checks the boundary. Type the input as the JSON:API document it is instead, and export the v1.1 document types (`JsonApiDocument`, `JsonApiResource`, `JsonApiRelationship`, `JsonApiResourceIdentifier`, `JsonApiLinks`, ...) so callers can type the raw response. `T` stays unconstrained, and no longer has a default: what comes out depends on the endpoint, so the caller names the type it expects (an unnamed `T` infers `unknown`). The implementation returns `any` internally rather than describing a structure that would be cast to `T`. The deprecated `deserializePage`/`deserializePages` aliases get the same input type. Type-level specs live in `deserialize.types.spec.ts`, and `pnpm typecheck` now also compiles the specs (they were excluded before). BREAKING CHANGE: TypeScript callers must pass a value typed as `JsonApiDocument` (or structurally compatible with it). Values typed `unknown` and documents with numeric ids no longer compile. Runtime behaviour is unchanged.
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.
deserialize<T = unknown>(document: unknown): Taccepts anything, so a caller can annotate its API call with the deserialized type, pass it in, and nothing checks the boundary. Type the input as the JSON:API document it is instead, and export the v1.1 document types (JsonApiDocument,JsonApiResource,JsonApiRelationship,JsonApiResourceIdentifier,JsonApiLinks, ...) so callers can type the raw response.Tstays unconstrained, and no longer has a default: what comes out depends on the endpoint, so the caller names the type it expects (an unnamedTinfersunknown). The implementation returnsanyinternally rather than describing a structure that would be cast toT.The deprecated
deserializePage/deserializePagesaliases get the same input type.Type-level specs live in
deserialize.types.spec.ts, andpnpm typechecknow also compiles the specs (they were excluded before).BREAKING CHANGE: TypeScript callers must pass a value typed as
JsonApiDocument(or structurally compatible with it). Values typedunknownand documents with numeric ids no longer compile. Runtime behaviour is unchanged.