Cannot find name 'jsdom'
hello simon
In my project jest-environment-jsdom-global can run normally,
But jslint will prompt me 'Cannot find name 'jsdom'
my tslint version is "^5.10.0",should i ignore this waring?
Hm, strange one. I've only used eslint, but actually, the behavior you're describing is what I would have expected to happen there, too.
Since I haven't used tslint before, I'm not sure what the solution is. Ignoring may be the best option.
Open to any suggestions or PRs on this, though!
Add this line will solve this problem
declare var jsdom: any
But I think this is not an elegant solution
Another solution is to refer to global.jsdom, rather than jsdom. Again, though, this lacks elegance.
Any elegant solutions planned for TS users? @simon360 where are you getting global.jsdom from?
@QuantumInformation this isn’t on my radar right now, but I’d love to see a pull request!
FYI, for others that have experienced this issue, we fixed this by referring to global.jsdom as @simon360 offered as a potential solution but we also had to declare JSDOM in our globals.d.ts file like this:
import { JSDOM } from 'jsdom';
declare global {
namespace NodeJS {
interface Global {
jsdom: JSDOM;
}
}
}
For more information on the globals file: https://www.typescriptlang.org/docs/handbook/declaration-files/templates/global-d-ts.html
// global.d.ts
import { JSDOM } from 'jsdom';
declare global {
namespace globalThis {
const jsdom: JSDOM;
}
}
easier
// global.d.ts
import { JSDOM } from 'jsdom';
declare global {
const jsdom: JSDOM;
}