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

Can't import recording appender from typescript #967

Closed
daniel-beard opened this issue Nov 19, 2019 · 3 comments · Fixed by #1103
Closed

Can't import recording appender from typescript #967

daniel-beard opened this issue Nov 19, 2019 · 3 comments · Fixed by #1103
Labels
enhancement New feature or request
Milestone

Comments

@daniel-beard
Copy link

Doesn't look like the types for the recording appender are defined maybe?

import * as recording from "log4js/lib/appenders/recording";

Outputs:

TSError: TypeScript diagnostics (customize using `[jest-config].globals.ts-jest.diagnostics` option):
src/utils/logging.ts:2:27 - error TS7016: Could not find a declaration file for module 'log4js/lib/appenders/recording'. '/project/node_modules/log4js/lib/appenders/recording.js' implicitly has an 'any' type.
  Try `npm install @types/log4js` if it exists or add a new declaration (.d.ts) file containing `declare module 'log4js/lib/appenders/recording';`

2 import { recording } from 'log4js/lib/appenders/recording';
                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Is there a way for me to import this appender in typescript?

@nomiddlename
Copy link
Collaborator

It's defined in types/log4js.d.ts but that's from the perspective of using log4js.configure with a recording appender in the config rather than importing it directly in a test. I don't use typescript, so I rely on users to help me with the types - so if you feel like making a PR with the changes you need that would be awesome.

@daniel-beard
Copy link
Author

daniel-beard commented Nov 20, 2019

I have not been able to figure out how to do this yet in the source project, however, so far have been able to use this in my project under typings/recording.d.ts:

declare module 'log4js/lib/appenders/recording' {
  import * as log4js from 'log4js';
  export function replay(): log4js.LoggingEvent[];
  export function reset(): void;
}

Which isn't great, but works. Will keep investigating, but am pretty new to TS.

@polo-language
Copy link
Contributor

TypeScript bindings to work with the recording are available in PR #1103. Let me know if it looks good to you.

@lamweili lamweili added this to the 6.4.0 milestone Jan 18, 2022
@lamweili lamweili added the enhancement New feature or request label Apr 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants