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

Typescript typings for apm-rum-react #624

Open
poserdonut opened this issue Feb 14, 2020 · 6 comments · May be fixed by #1343
Open

Typescript typings for apm-rum-react #624

poserdonut opened this issue Feb 14, 2020 · 6 comments · May be fixed by #1343

Comments

@poserdonut
Copy link

Hi!

We are trying to use the apm-rum-react package. However we are using typescript and there don't seem to be any typings for apm-rum-react.

@Cliftonz
Copy link

Cliftonz commented Mar 2, 2020

I am using apm-rum-react with typescript too and would like to have the typings in this package.

@vigneshshanmugam
Copy link
Member

The typings is already up published for @elastic/apm-rum and apm-rum-react and angular are just wrappers so we have not published anything for those at the moment.

We will try to add typings sooner for these package as well.

@dobesv
Copy link
Contributor

dobesv commented Mar 13, 2020

Here's the typing file I created in my project for this:

// elastic__apm-rum-react.d.ts
declare module '@elastic/apm-rum-react' {
  import { ComponentType } from 'react';
  import { Route } from 'react-router';
  export const ApmRoute: typeof Route;

  /**
   * Wrap a component to record an elastic APM transaction while it is rendered.
   *
   * Usage:
   *  - Pure function: `withTransaction('name','route-change')(Component)`
   *  - As a decorator: `@withTransaction('name','route-change')`
   */
  export const withTransaction: (
    name: string,
    eventType: string,
  ) => <T>(component: ComponentType<T>) => ComponentType<T>;
}

@siennathesane
Copy link

Also using React, would be nice to have typings...

@vivcogit vivcogit linked a pull request Feb 19, 2023 that will close this issue
@vivcogit
Copy link

Hi! I opened a pull request with only adding declarations. What do you think about full rewriting on typescript? If maintainers approved this idea I can do it with apm-rum-react

@dangkhoipro
Copy link

// elastic__apm-rum-react.d.ts
declare module '@elastic/apm-rum-react' {
  import { ComponentType } from 'react';
  import { Route } from 'react-router';
  export const ApmRoute: typeof Route;

  /**
   * Wrap a component to record an elastic APM transaction while it is rendered.
   *
   * Usage:
   *  - Pure function: `withTransaction('name','route-change')(Component)`
   *  - As a decorator: `@withTransaction('name','route-change')`
   */
  export const withTransaction: (
    name: string,
    eventType: string,
  ) => <T>(component: ComponentType<T>) => ComponentType<T>;
}

The Elastic doc uses import { ApmRoutes } from '@elastic/apm-rum-react', so I add ApmRoutes type to the module

import { Route, Routes } from 'react-router';
export const ApmRoute: typeof Route;
export const ApmRoutes: typeof Routes;

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.

7 participants