1

I'm using grunt-typescript, which is compiling all my *.ts files. I'm using both angular-mocks.d.ts and node.d.ts, however I'm referencing them separately in my actual ts files. I'm using angular-mocks only for jasmine testing, and I'm using node in my server.ts file.
The problem I'm having is that, even though they're referenced separately, when they are compiled within grunt-typescript, it seems to dump them together somehow so that their two different definitions of "module" end up conflicting. If I build my server.ts file by itself using tsc (which references node.d.ts), it builds fine. The two should never actually coincide and so for me isn't really a conflict except it's becoming one in grunt-typescript which seems to dump all the *.d.ts files together as it's compiling. I assume this is because it's building all of my *.ts files together and so ends up pulling the *.d.ts files together into a common space.

The error I get:

c:/node/bills/typings/node/node.d.ts(37,13): error TS2134: Subsequent variable declarations must have the same type. Variable 'module' must be of type '(...modules: any[]) => any', but here has type '{ exports: any; require(id: string): any; id: string; filename: string; loaded: boolean; parent: any; children: any[]; }'.

angular-mocks.d.ts "module" definition:

declare var module: (...modules: any[]) => any;

node.d.ts "module" definition:

declare var module: {
    exports: any;
    require(id: string): any;
    id: string;
    filename: string;
    loaded: boolean;
    parent: any;
    children: any[];
}

2 Answers 2

1

This ended up working for me. I split my test .ts files into a separate typescript run. That causes it not to run together my test declarations and my runtime declarations. With those separated, the module ambient declarations no longer conflict.

    typescript: {
        options:
        {
            target: 'es5', //or es3
            base_path: '',
            sourcemap: true,
            declaration: false
        },
        server: {
            src: ['*.ts']
        },
        test: {
            src: ['test/*.ts']
        }
    },

    watch: {
        files: ['*.ts', 'test/*.ts'],
        tasks: ['typescript:server', 'typescript:test']
    }
Sign up to request clarification or add additional context in comments.

Comments

1

This is a known problem!

It has been made a pull request/merge ..

Workaround is to use angular.mock.module instead of module.

1 Comment

more than a workaround! the typings definitions for angular-mocks recommends you always use angular.mock.module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.