Skip to content

fix(repository): allow @property.array on nullable array properties - #11908

Open
utsxvrai wants to merge 1 commit into
loopbackio:masterfrom
utsxvrai:fix/property-array-nullable
Open

utsxvrai wants to merge 1 commit into
loopbackio:masterfrom
utsxvrai:fix/property-array-nullable

Conversation

@utsxvrai

Copy link
Copy Markdown

TypeScript emits Object as the design type for union types such as string[] | null or string[] | undefined, so @property.array threw "can only decorate array properties" for nullable array properties. This accepts Object as well as Array as the design type; non-array types like string or a model class still throw.

Trade-off: because TypeScript gives no type info for unions, a non-array union like Product | null decorated with @property.array will now also pass this check instead of throwing. That seemed better than rejecting every nullable array, but happy to change it if you'd prefer a different approach.

Fixes #8466

Checklist

  • DCO (Developer Certificate of Origin) signed in all commits
  • npm test passes on your machine (packages/repository: 417 passing)
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • API Documentation in code was updated
  • Documentation in /docs/site was updated
  • Affected artifact templates in packages/cli were updated
  • Affected example projects in examples/* were updated

TypeScript emits `Object` as the design type for union types such as
`string[] | null`, which made @property.array throw for nullable arrays.

Fixes loopbackio#8466

Signed-off-by: utsxvrai <utsavrai2115@gmail.com>

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

@property.array doesn't work if nulls are allowed

1 participant