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

'SpecReporter' is not assignable to type 'Reporter | CustomReporter' #588

Closed
2 of 3 tasks
squidfunk opened this issue Mar 12, 2021 · 8 comments · Fixed by #600
Closed
2 of 3 tasks

'SpecReporter' is not assignable to type 'Reporter | CustomReporter' #588

squidfunk opened this issue Mar 12, 2021 · 8 comments · Fixed by #600

Comments

@squidfunk
Copy link

Issue guidelines

Bug report

Check with "x":

Current behavior

I'm encountering a type error when configuring the spec reporter, probably related to the latest @types/jasminepackage:

index.ts(91,27): error TS2345: Argument of type 'SpecReporter' is not assignable to parameter of type 'Reporter | CustomReporter'.
  Type 'SpecReporter' is not assignable to type 'CustomReporter'.
    Types of property 'suiteStarted' are incompatible.
      Type '(result: import("node_modules/jasmine-spec-reporter/built/spec-reporter").CustomReporterResult) => void' is not assignable to type '(result: jasmine.CustomReporterResult) => void'.
        Types of parameters 'result' and 'result' are incompatible.
          Type 'jasmine.CustomReporterResult' is not assignable to type 'import("node_modules/jasmine-spec-reporter/built/spec-reporter").CustomReporterResult'.
            Types of property 'duration' are incompatible.
              Type 'number | null' is not assignable to type 'string | undefined'.
                Type 'null' is not assignable to type 'string | undefined'.

Expected behavior

No type error, assignment works as expected.

Minimal reproduction of the problem with instructions

Package versions:

  • @types/jasmine: 3.6.6
  • jasmine: 3.6.4
  • jasmine-spec-reporter: 6.0.0
const jasmine = new Jasmine({})
jasmine.env.clearReporters()
jasmine.env.addReporter(new SpecReporter({
  spec: { displayStacktrace: StacktraceOption.RAW }
}))

Possible fix

Change the typing of duration to number | null here:

export interface CustomReporterResult extends jasmine.CustomReporterResult {
duration?: string;
}

@SetupCoding
Copy link

SetupCoding commented Mar 12, 2021

As a workaround you can do

import CustomReporter = jasmine.CustomReporter;


jasmine.getEnv().addReporter((new SpecReporter() as unknown) as CustomReporter);

@squidfunk
Copy link
Author

Thanks! I just added a @ts-ignore above the line with the same result. This issue was meant as an FYI that the typings might need to be updated 😊

@bcaudan
Copy link
Owner

bcaudan commented Mar 12, 2021

Indeed, it seems to have been detected by dependabot as well #585

I'll look into it, thanks for the heads up

@coyoteecd
Copy link

@bcaudan any update? I forked and looked at it, but it seems there's quite some changes involved

@bcaudan
Copy link
Owner

bcaudan commented Apr 1, 2021

I have started to look into it but I have to look deeper into the spec duration from jasmine to see if there is still a need for jasmine-spec-reporter to compute it as well.
New lockdown starting this weekend for me, so I should come back to it soon 🤞

@coyoteecd
Copy link

Covid-19 helping open source development 😁

@bcaudan
Copy link
Owner

bcaudan commented Apr 10, 2021

A fix is available in jasmine-spec-reporter@7.0.0

@dominionikpeawujor
Copy link

As a workaround you can do

import CustomReporter = jasmine.CustomReporter;


jasmine.getEnv().addReporter((new SpecReporter() as unknown) as CustomReporter);

This saved me after days of debugging. Thank you @SetupCoding

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

Successfully merging a pull request may close this issue.

5 participants