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

Guide for Typescript #96

Open
wolfcomp opened this issue Jan 18, 2022 · 1 comment
Open

Guide for Typescript #96

wolfcomp opened this issue Jan 18, 2022 · 1 comment

Comments

@wolfcomp
Copy link

wolfcomp commented Jan 18, 2022

Would it be possible to add a typescript guide in the markdown to this for future uses.

Made this based on the README.md documentation should match up with what is written in it

interface CountOptions<T> {
    noReady?: boolean;
    nonReactive?: boolean;
    countFromField?: string | ((doc: T) => any);
    countFromFieldLength?: string | ((doc: T) => any);
    noWarnings?: boolean;
}

declare namespace Counts {
    function get(name: string): number;
    function publish<T>(subscription: Subscription, name: string, cursor: Mongo.Cursor<T, T>, options?: CountOptions<T>): void;
    function has(name: string): boolean;
    function noWarnings(): void;
}

Added this to the root folder in my project as publish-counts-d-ts and seems to work from what VSCode tells me and the fact I had no compile errors or runtime errors.

@67726e
Copy link

67726e commented Feb 27, 2023

In VS Code I was still receiving errors on the import statement:

import { Counts } from 'meteor/tmeasday:publish-counts';

As such, I had to make some slight modifications:

declare module "meteor/tmeasday:publish-counts" {
    export namespace Counts {
        interface CountOptions<T> {
            noReady?: boolean;
            nonReactive?: boolean;
            countFromField?: string | ((doc: T) => any);
            countFromFieldLength?: string | ((doc: T) => any);
            noWarnings?: boolean;
        }

        function get(name: string): number;
        function publish<T>(subscription: Subscription, name: string, cursor: Mongo.Cursor<T, T>, options?: CountOptions<T>): void;
        function has(name: string): boolean;
        function noWarnings(): void;
    }
}

Thank you for doing the heavy-lifting here @wolfcomp

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

2 participants