Skip to content
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

PrimaryData should include null #180

Open
earthlyreason opened this issue Aug 31, 2020 · 0 comments
Open

PrimaryData should include null #180

earthlyreason opened this issue Aug 31, 2020 · 0 comments

Comments

@earthlyreason
Copy link

The JSON:API spec says:

Primary data MUST be either:

  • a single resource object, a single resource identifier object, or null, for requests that target single resources
  • an array of resource objects, an array of resource identifier objects, or an empty array ([]), for requests that target resource collections

Note "or null" in the first condition.

So the following code should typecheck:

export const doc: JSONAPI.Document = { data: null };

Instead, it gives the following error:

Type 'null' is not assignable to type 'PrimaryData<string, AttributesObject<{ [k: string]: Value; }>>'. [2322]

This is because the PrimaryData type, which is used as the type of data in DocWithData is an interface that assumes the value is an existing object.

Is this intentional?

Expected behavior
The above should typecheck, but it gives the indicated error.

System Information (please complete the following information):

  • OS: N/A
  • Browser N/A
  • TypeScript Version 4 (but would apply to all versions)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant