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

Add missing types to FieldSet interface. #280

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

Conversation

pciacka
Copy link

@pciacka pciacka commented Sep 19, 2021

Why

When you have lookup field in the table that refers to the column of type number or boolean, it's impossible to define its type as number[] nor boolean[]. In such situation the following compiler's error is reported.

Type 'ServiceFields' does not satisfy the constraint 'FieldSet'.
  Property 'price' is incompatible with index signature.
    Type 'number[]' is not assignable to type 'string | number | boolean | Collaborator | readonly Collaborator[] | readonly string[] | readonly Attachment[] | undefined'.
      Type 'number[]' is not assignable to type 'readonly Attachment[]'.
        Type 'number' is not assignable to type 'Attachment'.

You can always defined such fields as string[]. However, this requires to cast types later in the code. For example, when field is numeric, the casting looks like the following:

fields.price[0] as unknown as number

This works, but that's not be best practice using TypeScript.

What

This PR resolves above issue by extending FieldSet interface by ReadonlyArray<number> and ReadonlyArray<boolean> types.

@jamescrowley
Copy link

jamescrowley commented Jan 22, 2022

This would be great to get fixed...

There's also the somewhat weird case that when this lookup field is a boolean and it's set to false/unchecked, it actually comes back as null in the API instead of false

Screenshot 2022-01-22 at 11 38 17

@albertlieyingadrian
Copy link

Also facing the same issue and need this proposal to be merged

Copy link

@albertlieyingadrian albertlieyingadrian left a comment

Choose a reason for hiding this comment

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

LGTM

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.

None yet

3 participants