-
Notifications
You must be signed in to change notification settings - Fork 72
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
Comments
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 😄 |
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. |
Yes, definitely open to it! Apollo itself is already TypeScript so that should help too |
It might be easier as a first step just to provide type definitions for the public API and leave the code in However, I would obviously prefer to see the whole addon rewritten in TypeScript, so I don't want to derail that effort. |
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 // 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'}) |
Yes please! |
It would be nice to have TypeScript type definitions or rewrite the addon to TypeScript itself.
The text was updated successfully, but these errors were encountered: