Open
Description
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)
Metadata
Metadata
Assignees
Labels
No labels