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

TS attachment required fields #277

Open
MalkovVladimir opened this issue Aug 12, 2021 · 3 comments · May be fixed by #358 or grepdemos/airtable.js#6
Open

TS attachment required fields #277

MalkovVladimir opened this issue Aug 12, 2021 · 3 comments · May be fixed by #358 or grepdemos/airtable.js#6
Labels

Comments

@MalkovVladimir
Copy link

Airtable documentation:

When creating an attachment, url is required, and filename is optional.

Attachment interface:

export interface Attachment {
    id: string;
    url: string;
    filename: string;
    size: number;
    type: string;
    thumbnails?: {
        small: Thumbnail;
        large: Thumbnail;
        full: Thumbnail;
    };
}

filename, size, type etc. not so optional.

Please do props optional or split type for different actions (create/update/delete).

@albreyb
Copy link
Contributor

albreyb commented Mar 9, 2022

Hey @MalkovVladimir, thank you for the suggestion. Our team will review and get back to you when we've decided how to move forward.

@albreyb albreyb added the bug label Mar 9, 2022
@tresorama
Copy link

tresorama commented Oct 4, 2022

It will be great to have this bug fixed.
This bug occurs both when using AirtableTable.create() and when using AirtableTable.update().

Until the bug is fixed, i managed this bug like this:

//
const AiirtableClient = new Airtable({ apiKey: AIRTABLE_API_KEY });
const AirtableBase = AirtableClient.base(AIRTABLE_BASE_ID);
const TableBooks = AirtableBase(AIRTABLE_TABLE_ID_BOOKS);

const createNewRecord = () => {
  return {
    fields: {
    pic: [{ url: 'http://my-fancy-image.com/imageeeeee.jpg' }],
    title: "My Superb Book",
    year: "2001",
  }
};

/* ============================================== */
//  before - this trigger TS error
/* ============================================== */
const newRecord = createNewRecord();
const createdRecords = await TableBooks.create([newRecord]); // TS-Error ...
const createdRecord = createdRecords[0]; // TS-Error ...

/* ============================================== */
// after - this illude TS and suppress error
/* ============================================== */

// TODO: there is a bug in the Airtable code, and an open issue
// https://github.com/Airtable/airtable.js/issues/277
// When the bug is resolved update the use of next line

const newRecord_tsErrorSolutionHack = createNewRecord() as unknown as { fields: Airtable.FieldSet };
const createdRecords = await TableBooks.create([newRecord_tsErrorSolutionHack]);
const createdRecord = createdRecords[0];

Happy coding.

@naclcaleb
Copy link

@albreyb still having this issue in 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants