I've been searching around for information on creating custom Jasmine matchers using TypeScript and it seems like a common issue. However, none of the solutions I've come across have worked for me.
My setup includes:
{
"typescript": "2.3.2",
"jasmine-core": "2.6.1",
"@types/jasmine": "2.5.47"
}
I am struggling to get Typescript to merge the namespace declaration that contains my custom matcher definition.
When adding the following code snippet:
declare namespace jasmine {
interface Matchers<T> {
toBeAnyOf(expected: jasmine.Expected<T>, expectationFailOutput?: any): boolean;
}
}
This causes other types previously declared in the jasmine
namespace to be hidden. Compiler errors are thrown such as:
[ts] Namespace 'jasmine' has no exported member 'CustomMatcherFactories'
[ts] Namespace 'jasmine' has no exported member 'CustomMatcher'.
Is there a proper way to add a custom matcher and ensure compatibility with Typescript?
Another complication arises when using the tslint:recommended
ruleset which disallows the usage of keywords like namespace
or module
. As a result, I had to disable the linter or modify the rule in order to proceed. It's unclear how one might extend definitions if this approach is considered "not recommended".