Document Service Input Types#
The @strapi/types package exposes TypeScript types for every argument passed into the Document Service (create, update, findOne, findMany, etc.). These input types are distinct from result/read types ā they model what callers write, not what the runtime returns.
Entry point: packages/core/types/src/modules/documents/params/attributes/index.ts
The core type is GetValues<TSchemaUID>, which maps a content-type UID to its input shape. Optional schema attributes become optional properties; required attributes use the -? modifier and remain strictly required. The companion GetValue<TAttribute> resolves each attribute's accepted value union (relations, dynamic zones, components, booleans, numbers, dates, and a fallback to Schema.Attribute.Value).
Higher-level param shapes ā data, filters, populate, pagination, status, locale ā are composed in packages/core/types/src/modules/documents/params/index.ts. Partial input (used by update) is handled by PartialInput<TSchemaUID> in params/data.ts. Relation-specific shapes such as LongHandDocument, PositionalArguments, and PartialUpdate live in params/attributes/relations.ts.
Optional Fields and null vs. undefined#
The distinction between null and undefined is intentional and runtime-backed:
nullmeans write NULL to the database. TheprocessDatafunction in the database entity manager explicitly preservesnulland passes it to knex's INSERT/UPDATE.undefined(or an absent key) means skip this column.processDataiterates schema attributes and callscontinuewheneverdata[attributeName]isundefinedā noin/hasOwnPropertycheck is involved, so{}and{ field: undefined }are identical to the database layer.
Because of this runtime equivalence, optional input properties accept undefined explicitly. Non-nullable scalars do not accept null ā the type fixture asserts this with @ts-expect-error. Required attributes retain the -? modifier and reject both missing values and explicit undefined.
exactOptionalPropertyTypes Compatibility#
TypeScript's exactOptionalPropertyTypes flag tightens optional properties: p?: T rejects { p: undefined } and only accepts a fully absent key. Without explicit | undefined on optional input types, consumers compiling with this flag get TS2375/TS2379 errors when forwarding their own optional fields into data.
What changed#
Two PRs addressed this ā #27288 and #27349 ā with the same approach:
-
GetValuesoptional branch ā changed from?: GetValue<...>to?: GetValue<...> | undefinedfor optional attributes, and added| undefinedtoid?/documentId?. The required branch (-?) is unchanged. -
PartialWithUndefined<T>utility ā introduced inpackages/core/types/src/utils/object.tsas aPartial-like helper that also unionsundefinedinto every property value type ([K]?: T[K] | undefined). Used instead of barePartial<T>wherever a partial input shape is built ā specificallyPartialInput<TSchemaUID>indata.tsandPartialUpdateinrelations.ts. -
Params-level widening ā optional fields across
params/index.ts,pagination.ts, andstatus.tswere widened to?: T | undefined, coveringlocale,status,hasPublishedVersion,publicationFilter,page,pageSize,start, andlimit. -
Relation inputs ā
LongHandDocument.locale?, positional args (before,after,start,end), andposition?inrelations.tswere widened to include| undefined.
Scope and backwards compatibility#
Adding | undefined to an optional property is a no-op when exactOptionalPropertyTypes is off (TypeScript already implicitly includes undefined for ? properties under default settings). Strapi's own tsconfig does not enable this flag; the changes are purely for consumers who do.
These changes apply only to input/write types. Result/read types (Schema.Attribute.GetValues and friends) are intentionally excluded ā widening those would weaken guarantees about data returned from the API.
Test coverage#
A dedicated fixture at packages/core/types/tests/exact-optional-property-types.ts is compiled with exactOptionalPropertyTypes: true via its own tests/tsconfig.json and is wired into yarn workspace @strapi/types test:ts. It asserts that optional fields accept undefined, required fields reject it, non-nullable scalars reject null, and top-level params (locale, status, fields, populate, etc.) accept undefined.
Key Files at a Glance#
| File | Purpose |
|---|---|
params/attributes/index.ts | GetValues, GetValue, scalar value aliases |
params/attributes/relations.ts | Relation input shapes (LongHandDocument, PositionalArguments, PartialUpdate) |
params/data.ts | Input<TSchemaUID>, PartialInput<TSchemaUID> |
params/index.ts | Top-level param composition (data, filters, populate, locale, status, pagination) |
params/pagination.ts | Pagination param types (page, pageSize, start, limit) |
params/status.ts | Publication status params (status, hasPublishedVersion, publicationFilter) |
utils/object.ts | PartialWithUndefined<T> helper |
tests/exact-optional-property-types.ts | EOPT fixture (compiled separately with the flag on) |