I've been looking around and this question seems like a recurring thing. However, none of the solutions I've found seem to work for me.
Using the following:
{
"typescript": "2.3.2",
"jasmine-core": "2.6.1",
"@types/jasmine": "2.5.47"
}
I can't get Typescript to merge the namespace declaration containing my custom matcher definition.
Adding this:
declare namespace jasmine {
interface Matchers<T> {
toBeAnyOf(expected: jasmine.Expected<T>, expectationFailOutput?: any): boolean;
}
}
Hides every other type previously declared on jasmine
. Compiler outputs errors such as:
[ts] Namespace 'jasmine' has no exported member 'CustomMatcherFactories'
[ts] Namespace 'jasmine' has no exported member 'CustomMatcher'.
Is there any proper way to add a custom matcher and make it play nicely with Typescript?
There's an additional issue with tslint
if you are using tslint:recommended
ruleset. Those rules disallow the usage of namespace
or module
keywords, so I had to disable the linter (or change the "no-namespace"
rule) in order to try this out. Unsure how one would get around extending definitions if this is "not recommended".
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…