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

Deprivatize and export more internal TS definitions #58

Open
billdami opened this issue Mar 2, 2022 · 4 comments
Open

Deprivatize and export more internal TS definitions #58

billdami opened this issue Mar 2, 2022 · 4 comments

Comments

@billdami
Copy link

billdami commented Mar 2, 2022

It would be helpful for consuming apps to have access to more internal TS types in glimmer-apollo, such as QueryResource. When typing things like component arguments, you currently would have to re-define the types if you want to pass in a glimmer-apollo query as an arg, for example:

interface MyComponentArgs {
    query: {
         loading: boolean;
         error?: string;
         data: {
              //...
         };
    }
}
@billdami
Copy link
Author

@josemarluedke any thoughts on this?

Currently in my app I've worked around this by just creating a types/glimmer-apollo-tmp/index.d.ts with

declare module 'glimmer-apollo-tmp' {
    //redeclared all the missing/private glimmer-apollo types here...
}

And just importing from that in my app when I need to

import { QueryResource } from 'glimmer-apollo-tmp';

export default class MyRoute extends Route {
    setupController(
        controller: MyController,
        model: QueryResource<MyQuery, MyQueryVariables>,
        transition: Transition
    ) {
        super.setupController(controller, model, transition);
        //other logic...
    }
}

I'm happy to put togther a PR for this, unless you have any objections to making those types public.

@xomaczar
Copy link

👍 @billdami would we very helpful for us as well

@bitwolfe
Copy link

bitwolfe commented May 10, 2022

This might even be necessary to make TypeScript understand the return types of useQuery and useMutation etc when it tries to build declarations if you have declaration: true in your tsconfig.json (which is the default now when you install ember-cli-typescript).

Currently the problem we run into is TypeScript complaining when it tries to build the declarations as apparently it doesn't take inferred types into account.

Public property 'myQuery' of exported class has or is using name 'QueryResource' from external module "node_modules/glimmer-apollo/dist/index" but cannot be named. ts(4029)

Apparently the solution is to import QueryResource and explicitly set the type of myQuery, but that is not possible as QueryResource is not exported.

See for more info on this:

microsoft/TypeScript#5711
microsoft/TypeScript#9944

@josemarluedke
Copy link
Owner

josemarluedke commented May 17, 2022

We export a set of utility types that allows to extract args and result of useQuery, useMutation and useSubscription.

I think we are missing docs for these, but you can import them like so:

import type { UseQuery, UseMutation, UseSubscription } from 'glimmer-apollo';

Using them is quite simple:

import type { UseQuery } from 'glimmer-apollo';

export default class MyRoute extends Route {
    setupController(
        controller: MyController,
        model: UseQuery<MyQuery, MyQueryVariables>['result'],
        transition: Transition
    ) {
        super.setupController(controller, model, transition);
        //other logic...
    }
}

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

No branches or pull requests

4 participants