I'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
> [email protected] 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
Did you put that code in a separate .d.ts file? If you want to create a reproduction of the issue on GitHub for quick debugging I can probably take a look how it should work for you and submit a patch back.
@blakeembrey I did try a separate file. and in the same file as the tests, I'm not finding any guidance on which is the recommended way to go about it unfortunately.
The project I'm working on is on GH here: https://github.com/gareththegeek/corewar if you grab it and take a look at the ExecutiveTests.ts.ignore that's the one I'm having trouble with. Remove the ignore from the filename npm i > npm test and you should see what I'm seeing.
That file has the snippet in file, but I'm happy to move it about to get things working.
Thanks for the response by the way, if I can provide any assistance or info on the project let me know.
It works fine for me. There's plenty of instructions around and unfortunately ts-node isn't the best place to find them.
.d.ts file because if it's in the same .ts file all you're doing is declaring a local namespace (it's a confusing part of TypeScript, but once you add import or export to the top level of a .ts file it's a module now, no longer interacting with the global scope).d.ts file in compilation. The normal way to do that is by including it via tsconfig.json. You can, however, also use a reference.Here's the test that worked locally for me:
npm i @types/jasmine
declare namespace jasmine {
export interface Matchers<T> {
toEqualInstruction(expected: any): boolean;
}
}
/// <reference path="interfaces.d.ts" />
expect(10).toEqualInstruction(10)
tsc test.ts
Unfortunately that example doesn't work my end :(

c:\github\gareththegeek\corewar>tsc simulator/tests/DemoTest.ts
simulator/tests/DemoTest.ts(3,12): error TS2339: Property 'toEqualInstruction' does not exist on type 'Matchers<number>'.
I'm not quite sure what's wrong here as by the sounds of things I'm doing things correctly (once the d.ts is in its own file?)
Arg, it just twigged....
once you add import or export to the top level of a .ts file it's a module now, no longer interacting with the global scope
As you can see from my screenshot I need to import an interface into the matcher d.ts which I presume breaks things. I can switch it to an any and things work! thanks so much, been pulling my hair out for ages with this one.
Thanks, I was just responding that you missed that point 😄
One thing you try try if you need the import is wrapping it all in declare global {}. Haven't tested it yet, but it might work for your use-case.
If you want to add it in same .ts file you can do
declare global {
namespace jasmine {
interface Matchers<T> {
toEqualInstruction(expected: any): boolean;
}
}
}
Most helpful comment
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: