extending @types/jasmine interface / namespace doesn't recognise method
See original GitHub issueI’m using ts-node via jasmine-ts and have a custom matcher which extends the d.ts in @types\jasmine unfortunately ts-node doesn’t seem to pick up the new method.
I’m adding my method to the interface like so:
declare namespace jasmine {
interface Matchers<T> {
toEqualInstruction(expected: IInstruction): boolean;
}
}
but ts-node reports:
c:\github\gareththegeek\corewar>npm test
> corewar@1.0.0 test c:\github\gareththegeek\corewar
> nyc jasmine-ts
c:\github\gareththegeek\corewar\node_modules\ts-node\src\index.ts:307
throw new TSError(formatDiagnostics(diagnosticList, cwd, ts, lineOffset))
^
TSError: ⨯ Unable to compile TypeScript
simulator\tests\ExecutiveTests.ts (227,38): Property 'toEqualInstruction' does not exist on type 'Matchers<IInstruction>'. (2339)
simulator\tests\ExecutiveTests.ts (230,38): Property 'toEqualInstruction' does not exist on type 'Matchers<IInstruction>'. (2339)
I’ve posted this on SO here: https://stackoverflow.com/questions/47313578/cannot-extend-a-types-jasmine-interface in case this is not the right place for the issue.
All the info I’ve found says to do what I’ve done but I’m unable to work out quite why the interface isn’t being combined.
I see this issue in vscode intellisense as well so it may be more a .ts issue. Happy to help investigate to get to the bottom of things.
versions below if it’s of any help:
>ts-node --version
ts-node v3.3.0
node v8.9.1
typescript v2.6.1
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Create custom jasmine matcher using Typescript
That seems to indicate that the declare namespace jasmine statement is creating a new jasmine namespace rather than extending the existing one. So...
Read more >Extending various TypeScript type declarations
Check what is the name of the module / interface / namespace I want to extend. By hovering on process.env I can see...
Read more >Backbone.js
Backbone.js gives structure to web applications by providing models with key-value binding and custom events, collections with a rich API of enumerable ...
Read more >Google TypeScript Style Guide
Do not mark interfaces specially ( IMyInterface or MyFooInterface ) unless it's idiomatic in its environment. When introducing an interface for a class,...
Read more >Configuring Jest
You can retrieve Jest's defaults from jest-config to extend them if ... full list of methods and argument types see Reporter interface in ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

It works fine for me. There’s plenty of instructions around and unfortunately
ts-nodeisn’t the best place to find them..d.tsfile because if it’s in the same.tsfile all you’re doing is declaring a local namespace (it’s a confusing part of TypeScript, but once you addimportorexportto the top level of a.tsfile it’s a module now, no longer interacting with the global scope).d.tsfile in compilation. The normal way to do that is by including it viatsconfig.json. You can, however, also use a reference.Here’s the test that worked locally for me:
Thanks, I was just responding that you missed that point 😄
One thing you try try if you need the
importis wrapping it all indeclare global {}. Haven’t tested it yet, but it might work for your use-case.