-
-
Notifications
You must be signed in to change notification settings - Fork 245
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
TS: Bundle Type definition for use-analytics #51
Comments
Sounds good to me. Happy to have a PR on this 😃 How would this work exactly? Adding a Thanks! |
I see one of two ways to do this:
How do you think I should go about implementing it? |
I have never used tsd-jsdoc to generate ambient type declaration files from jsdoc comments. Not sure if jsdoc is able to express all the features of typescript. I could hand-code these declaration files, but keeping source and declaration file would be a pain as code evolves. What do you think of porting use-analytics into TS? |
If tsd-jsdoc is an issue, you can also have TypeScript generate .d.ts files from JSDoc: |
Hey @xthilakx The way that it works with analytics-core is like this:
I would like to evolve this and make it easier to do, I'm not sure we can make the jump to full on typescript at this moment though. A couple of options
I think #1 would be best to make sure types are always in sync. #2 would also work as the API shouldn't really change too much @orta Interesting! I didn't know this was a thing. Do you know of any example projects I can have a look at that are using this approach? |
@DavidWells How about we just port I would be happy to open a PR if that's cool with you. |
I'd rather not maintain a typescript package. Happy to accept a PR with the types tho.
|
|
Hey @saiichihashimoto good point. Do you know what the updated types should look like to export the |
I'm not sure how |
For those here looking for the proper types, this should cover the entire package: declare module 'use-analytics' {
import type { ComponentType, Context, FC, ReactNode } from 'react';
import type { AnalyticsInstance } from 'analytics';
export function withAnalytics<P extends object>(Component: ComponentType<P>): FC<P>;
export function useAnalytics(): AnalyticsInstance;
export function useTrack(): AnalyticsInstance['track'];
export function usePage(): AnalyticsInstance['page'];
export function useIdentify(): AnalyticsInstance['identify'];
export const AnalyticsConsumer: Context<AnalyticsInstance>['Consumer'];
export const AnalyticsContext: Context<AnalyticsInstance>;
export function AnalyticsProvider(props: {
instance: AnalyticsInstance;
children: ReactNode;
}): JSX.Element;
} I've also opened a PR to simply hardcode this in the package for now #389 |
It would be great if
use-analytics
npm package can bundle type definitions. It would help me get rid of this from my code:https://gitlab.com/trao/trao.dev/-/blob/master/global.d.ts#L11
I would be happy to file a PR to fix this.
The text was updated successfully, but these errors were encountered: