nylas-nodejs: Types seem to be wrong
Describe the bug
I’m fetching calendars. These are the keys for the data I’m seeing:
The types are nonetheless defined as:
export declare type CalendarProperties = {
name: string;
description: string;
location: string;
timezone: string;
readOnly?: boolean;
isPrimary?: boolean;
jobStatusId?: string;
metadata?: object;
hexColor?: string;
};
export default class Calendar extends RestfulModel implements CalendarProperties {
name: string;
description: string;
location: string;
timezone: string;
readOnly?: boolean;
isPrimary?: boolean;
jobStatusId?: string;
metadata?: object;
hexColor?: string;
static collectionName: string;
static attributes: Record<string, Attribute>;
constructor(connection: NylasConnection, props?: CalendarProperties);
save(params?: {} | SaveCallback, callback?: SaveCallback): Promise<this>;
saveRequestBody(): Record<string, unknown>;
getJobStatus(callback?: GetCallback): Promise<JobStatus>;
}
found in /node_modules/nylas/lib/models/calendar.d.ts
.
Notably, properties that should be camelCase
per the types are instead snake_case
per the api. This makes the types unusable and is overall a usability hit to the SDK.
To Reproduce
- Look at code.
- Look at data actually coming from the api. \
Expected behavior Types match.
SDK Version:
"nylas": "^6.9.0",
Additional context N/A
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 15
No problem - Thanks for taking the time to respond 😄
We’re using:
In our application at the moment, and it’s been a much smoother dev exp.
Thanks again for all your help and time on this
@birksy89 no problem at all! I did construct it and that’s where I derived my answer from. This was the code I used:
For each member of the loop, the two console.log statements gave me two different outputs:
for the .toJSON() call I got (similar to yours):
and in the plain console.log(threads) I got:
Note that in the second example how it’s camelCase and the variable is a
Date
as opposed to an epoch timestamp.Now mind you, you don’t need to call toJSON() directly yourself to trigger it. toJSON() is a built-in javascript function. Some libraries will call toJSON as part of a serialization call or something, hence triggering the conversion to snake_case.
Can you provide me more context on how your using your “threads” variable after you fetch the data from our API? If you can share the function code snippet that would give me more clues as to what is going on 😃. Thanks!