linagora / jmap-client-ts

JMAP 1.0 client library in TypeScript
MIT License
36 stars 16 forks source link

Specifying properties for jmapClient.email_get seems to be an issue #56

Closed jeserkin closed 3 years ago

jeserkin commented 3 years ago

Given

getEmailsWithSpecificProperties(emailIds: string[], properties: ?): Observable<IEmailGetResponse> {
    return from(this.fetchSession())
      .pipe(
        mergeMap(session => from(this.jmapClient.email_get({
          accountId: Object.keys(session.accounts)[0],
          ids: emailIds,
          fetchAllBodyValues: true,
          properties
        })))
      );
  }

What would properties type be, to accommodate provided method?

Based on the question, it seems to me, that properties?: (keyof Properties)[]; is not the desired way of specifying type.

alagane commented 3 years ago

What would properties type be, to accommodate provided method?

Partial<IEmailGetArguments> maybe?

If I understand correctly, properties should be used with ...properties instead of properties

jeserkin commented 3 years ago

Okay. So destructuring is not an option here, since there should be a property called properties.

Based on https://github.com/linagora/jmap-client-ts/blob/main/src/types.ts#L224-L230 and https://github.com/linagora/jmap-client-ts/blob/main/src/types.ts#L48-L51 it is unclear how this can be passed as an argument.

Partial doesn't seem to work as well.

image

I feel like it is difficult to define it type as method argument because it is marked as keyof, but I can be wrong about it.

alagane commented 3 years ago

This doesn't work? (keyof IEmailProperties)[]

jeserkin commented 3 years ago

As argument type?

alagane commented 3 years ago

Instead of the ? on your first example.

jeserkin commented 3 years ago

Okay. Didn't not expect, that it will work. Thanks. That resolved the issue.

chibenwa commented 3 years ago

Do we have code examples that could serve as documentation?

If you did not find it yourself, then others are likely not to find it too...

jeserkin commented 3 years ago

I guess only current discussion could serve as documentation for this specific example/problem, but I do support idea of Wiki page with example for different existing methods.

alagane commented 3 years ago

Do we have code examples that could serve as documentation?

If you did not find it yourself, then others are likely not to find it too...

This is more typescript advanced types problems than jmap-client-ts problems.

jeserkin commented 3 years ago

Also true, but still would be nice to have examples (Wiki on GitHub is a perfect place for it). Entirely possible, that my use case came up because of lack of knowledge about certain TypeScript aspect.