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

Property 'noticeError' does not exist on type 'MicroAgent' #608

Closed
jamesarosen opened this issue Jun 29, 2023 · 6 comments · Fixed by #613
Closed

Property 'noticeError' does not exist on type 'MicroAgent' #608

jamesarosen opened this issue Jun 29, 2023 · 6 comments · Fixed by #613
Labels
bug Something isn't working needs triage

Comments

@jamesarosen
Copy link

The types for MicroAgent don't include noticeError despite that appearing in the docs.

Description

The README has this code:

const microAgent1 = new MicroAgent(options_1)
// ...
// manually handle a JavaScript Error with microAgent1
try{
  ...
} catch(err) {
  microAgent1.noticeError(err)
}

But when I try that locally, TypeScript complains:

Property 'noticeError' does not exist on type 'MicroAgent'.ts(2339)

Steps to Reproduce

  1. Install @newrelic/[email protected]
  2. Create a TypeScript file with the following contents:
import { MicroAgent } from "@newrelic/browser-agent/loaders/micro-agent";

const agent = new MicroAgent({ /* some configuration */ });

try {
  throw new Error('test')
} catch (e) {
  agent.noticeError(error);
}

Expected Behavior

The code compiles

Your Environment

I haven't yet gotten to a runtime environment, but it will be running in Fastly's Compute@Edge, which mimics a ServiceWorker environment.

@jamesarosen jamesarosen added bug Something isn't working needs triage labels Jun 29, 2023
@workato-integration
Copy link

@jamesarosen
Copy link
Author

This sort of works:

import { MicroAgent } from "@newrelic/browser-agent/loaders/micro-agent";
import type { setAPI } from "@newrelic/browser-agent/loaders/api/api";

type NewRelicAPI = ReturnType<typeof setAPI>;

const agent = new MicroAgent({ /* config */ })
(agent as unknown as NewRelicAPI).noticeError(error, {});

A minor issue is that the second argument -- customAttributes -- isn't optional in the TypeScript types.

@cwli24
Copy link
Contributor

cwli24 commented Jul 6, 2023

Hi @jamesarosen , all the code excerpts in the README are in JS, as we do not have support for TS.

There's however a community-created typings for our agent's interface at: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/new-relic-browser . Please note we're not responsible for this typing. For more, see thread on this: https://forum.newrelic.com/s/hubtopic/aAX8W0000008YeBWAU/typescript-for-browser-agent.

@cwli24 cwli24 closed this as completed Jul 6, 2023
@jamesarosen
Copy link
Author

we do not have support for TS

You might want to remove this from your package.json then:

"types": "./dist/types/index.d.ts",
"typesVersions": {
  ">=4.2": {
    "*": [
      "dist/types/*"
    ]
  }
},

Having that in the published package.json implies (1) that you do support TypeScript and (2) that consumers don't need to rely on DefinitelyTyped for this package.

@patrickhousley
Copy link
Contributor

Typescript types generation cannot determine the actual types due to the dynamic nature of the agent. I will look into fixing the types generation in our build process.

@jamesarosen
Copy link
Author

Typescript types generation cannot determine the actual types due to the dynamic nature of the agent

I think you actually can by applying type predicates when mixing in the capabilities in configure/configure and api/api, though that would probably require writing the library in TypeScript rather than trying to generate types during the build process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants