nylas-nodejs icon indicating copy to clipboard operation
nylas-nodejs copied to clipboard

Separate Nylas @types package?

Open tvongaza opened this issue 1 year ago • 1 comments

Is your feature request related to a problem? Please describe.

We're integrating with Nylas and in our typescript front end code want to make use of types for the Nylas data. Turns out all the types are defined in the nylas-nodejs repo, but are inlined in the modes (example: https://github.com/nylas/nylas-nodejs/blob/main/src/models/event.ts#L35). We do not want to include the nodejs package for our front end code when we just need the types.

Describe the solution you'd like

It would be great to have a nylas maintained @types (via https://github.com/DefinitelyTyped/DefinitelyTyped or your own) package which defines all the typescript types. This could be used in your nodejs app, or front end code.

Describe alternatives you've considered

Currently I've just copied and pasted the types into my own types file as needed. It works, but will be prone to getting outdated if Nylas's types ever change.

Additional context

Example file:

export type NylasEvent = EventProperties & RestfulModelJSON & EventPropertiesAdditions;

interface EventPropertiesAdditions {
  updatedAt: number;
}

interface RestfulModelJSON {
  id: string;
  object: string;
  accountId: string;
  // [key: string]: any;
}

type EventProperties = {
  calendarId: string;
  when: WhenProperties;
  iCalUID?: string;
  messageId?: string;
  eventCollectionId?: string | number;
  title?: string;
  description?: string;
  owner?: string;
  participants?: EventParticipantProperties[];
  readOnly?: boolean;
  location?: string;
  busy?: boolean;
  status?: string;
  recurrence?: {
    rrule: string[];
    timezone: string;
  };
  masterEventId?: string;
  originalStartTime?: Date;
  capacity?: number;
  conferencing?: EventConferencingProperties;
  notifications?: EventNotificationProperties[];
  roundRobinOrder?: string[];
  metadata?: object;
  jobStatusId?: string;
  organizerEmail?: string;
  organizerName?: string;
  hideParticipants?: boolean;
  visibility?: string;
  customerEventId?: string;
  reminderMinutes?: string;
  reminderMethod?: EventReminderMethod;
  reminders?: EventReminderProperties;
};

export type WhenProperties = {
  startTime?: number;
  endTime?: number;
  startTimezone?: string;
  endTimezone?: string;
  time?: number;
  timezone?: string;
  startDate?: string;
  endDate?: string;
  date?: string;
  object?: string;
};

export type EventParticipantProperties = {
  email: string;
  name?: string;
  comment?: string;
  phoneNumber?: string;
  status?: string;
};

export type EventConferencingProperties = {
  provider: string;
  details?: EventConferencingDetailsProperties;
  autocreate?: {
    settings?: object;
  };
};

export type EventConferencingDetailsProperties = {
  meetingCode?: string;
  phone?: string[];
  password?: string;
  pin?: string;
  url?: string;
};

export enum EventNotificationType {
  Email = 'email',
  Sms = 'sms',
  Webhook = 'webhook',
}

export type EventNotificationProperties = {
  type: EventNotificationType;
  minutesBeforeEvent: number;
  url?: string;
  payload?: string;
  subject?: string;
  body?: string;
  message?: string;
};

export enum EventReminderMethod {
  Email = 'email',
  Popup = 'popup',
  Display = 'display',
  Sound = 'sound',
}

export type EventReminderProperties = {
  reminderMinutes?: string;
  reminderMethod?: EventReminderMethod;
};

tvongaza avatar May 01 '23 15:05 tvongaza

TypeScript has type-only imports that are always fully erased so that there is no remnant of them at runtime. You should be able to get the same effect as a @types/ package by using import type ... from 'nylas' and making nylas a devDependency.

joshuatshaffer avatar Jul 30 '24 18:07 joshuatshaffer