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

Migrate to TypeScript #140

Open
josemarluedke opened this issue Jul 5, 2018 · 6 comments
Open

Migrate to TypeScript #140

josemarluedke opened this issue Jul 5, 2018 · 6 comments

Comments

@josemarluedke
Copy link
Member

It would be nice to have TypeScript type definitions or rewrite the addon to TypeScript itself.

@bgentry
Copy link
Member

bgentry commented Jul 6, 2018

I haven't written any TypeScript yet myself, but I'd also love to see this. My understanding is that it should be possible to incrementally migrate the addon to use TS, is that accurate?

Contributions welcome 😄

@josemarluedke
Copy link
Member Author

Yes, it is possible to incrementally migrate the project to TypeScript. If you are open for it, I will start doing some work on that.

@bgentry
Copy link
Member

bgentry commented Jul 7, 2018

Yes, definitely open to it! Apollo itself is already TypeScript so that should help too

@josemarluedke josemarluedke changed the title TypeScript type definitions Migrate to TypeScript Aug 1, 2019
@dmzza
Copy link
Contributor

dmzza commented Oct 16, 2019

It might be easier as a first step just to provide type definitions for the public API and leave the code in .js for now. I've started writing type definitions for this to use in my own project, and I'm happy to open a PR if that would be useful.

However, I would obviously prefer to see the whole addon rewritten in TypeScript, so I don't want to derail that effort.

@josemarluedke
Copy link
Member Author

Adding type definitions seem to be a good alternative, however, it would be best if the project was written in TypeScript itself. This is the goal with my latest PRs moving native classes and modernizing the codebase of the addon.

Today we can add type definitions in the consuming app itself, that's how I have been doing for now in my apps. For reference, I will add my type definitions. Note that these rely on apollo-client types.

// types/ember-apollo-client/services/apollo.d.ts

declare module 'ember-apollo-client/services/apollo' {
  import Service from '@ember/service';

  import {
    MutationOptions,
    QueryOptions,
    WatchQueryOptions,
    SubscriptionOptions
  } from 'apollo-client';

  interface Options {
    apiURL: string;
    requestCredentials?: string;
  }

  export default class ApolloService extends Service {
    public options: Options;

    public clientOptions(): object;

    public link(): unknown;

    public mutate<T = object>(
      ots: MutationOptions,
      resultKey?: string
    ): Promise<T>;

    public query<T = object>(
      opts: QueryOptions,
      resultKey?: string
    ): Promise<T>;

    public watchQuery<T = object>(
      opts: WatchQueryOptions,
      resultKey?: string
    ): Promise<T>;

    public subscribe<T = object>(
      opts: SubscriptionOptions,
      resultKey?: string
    ): Promise<T>;
  }
}```


```ts
// types/ember-apollo-client/index.d.ts

import ComputedProperty from '@ember/object/computed';
import ApolloService from 'ember-apollo-client/services/apollo';

interface Opts {
  service: string;
}

export function queryManager(): ComputedProperty<ApolloService>; // @queryManager() foo, foo: queryManager()
export function queryManager(
  target: object,
  propertyKey: string | symbol
): void; // @queryManager foo
export function queryManager<T = ApolloService>(
  opts: Opts
): ComputedProperty<T>; // @queryManager({service: 'name'})

@knownasilya
Copy link
Contributor

Yes please!

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

Successfully merging a pull request may close this issue.

4 participants