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

Fix TS types for creating and updating records with attachment fields #358

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

okovpashko
Copy link

Fixes #277

I will appreciate suggestions and improvements regarding this change.

@@ -10,5 +10,5 @@ export interface FieldSet {
| Collaborator
| ReadonlyArray<Collaborator>
| ReadonlyArray<string>
| ReadonlyArray<Attachment>;
| ReadonlyArray<Attachment | CreateAttachment | AttachmentReference>;
Copy link
Author

@okovpashko okovpashko Mar 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only change I'm not sure about.

Without it, we get TS errors when passing fields with type eitherAttachmentReference or CreateAttachment to the create() or update() methods because the result of PartialFields has both fields' types and the indexed type from FieldSet:

interface MyFields extends FieldSet {
  name: string;
  files: Attachment[]
}

type PartialMyFields = PartialFields<MyFields>;

/*
The result type of PartialMyFields is
{
  [x: string]:
      | undefined
      | string
      | number
      | boolean
      | Collaborator
      | ReadonlyArray<Collaborator>
      | ReadonlyArray<string>
      | ReadonlyArray<Attachment | CreateAttachment | AttachmentReference>;
  name: string;
  files: (AttachmentReference | CreateAttachment)[]
}
*/

I will appreciate suggestions for a better solution.

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.

TS attachment required fields
1 participant