Whatever strategy you use, I strongly recommend you use the full path to 
bootstrap modules, *angular.mock.module*

just using the *module* variable (example 1) will cause collisions if you 
every have to install @types/node (or if a dependency ever installs it!)

FWIW, *angular.mock.module* works for me if I import angular like so:

import angular from 'angular';

But that might break for your build. I recommend keeping the import *, but 
also import angular-mocks:

*import * as angular from 'angular';*
*import 'angular-mocks';*

Hope it helps.

Read more: 
https://stackoverflow.com/questions/41617628/whats-the-correct-way-to-import-angular-mocks

On Thursday, January 26, 2017 at 6:05:14 AM UTC-5, james robb wrote:
>
> I've switched an angular 1 typescript project over to TS 2.0 and am using 
> @types/angular-mocks for the type definitions. As it stands, i'm unable to 
> work out how to actually import and use angular-mocks 'module', without 
> getting TS errors.
>
> All three of these ways actually work (as in, my tests run without any 
> errors, after being transpiled and loaded by systemjs), but they all result 
> in TS errors
>
> 1)
>
> import {module} from 'angular-mocks';
>
>
> beforeEach(module('blah'));
>
>
>
> systemjs config meta:
>
> meta: {
>     angular: {
>         format: 'global',
>         exports: 'angular'
>     },
>     'angular-mocks': {
>         format: 'global',
>         deps: ['angular']
>     }
>
> }
>
>
>
> TS error:
>
>
> error TS2305: Module '"/path/to/node_modules/@types/angular-mocks/index"' has 
> no exported member 'module'.
>
>
>
> 2)
>
>
> import * as angular from 'angular-mocks';
>
>
> beforeEach(angular.mock.module('blah'));
>
>
>
> systemjs config meta:
>
>
> meta: {
>     angular: {
>         format: 'global',
>         exports: 'angular'
>     },
>     'angular-mocks': {
>         format: 'global',
>         exports: 'angular',
>         deps: ['angular']
>     }
>
> }
>
>
>
> TS error:
>
>
> error TS2339: Property 'mock' does not exist on type 'typeof 
> "/path/to/node_modules/@types/angular...'.
>
>
>
> 3)
>
>
> import 'angular-mocks';
>
>
> beforeEach(module('blah'));
>
>
>
>
> systemjs config meta:
>
>
> meta: {
>     angular: {
>         format: 'global',
>         exports: 'angular'
>     },
>     'angular-mocks': {
>         format: 'global',
>         deps: ['angular']
>     }
>
> }
>
>
>
> TS Error:
>
>
> error TS2304: Cannot find name 'module'.
>
>
>
> ------------------------------------------------------------------------
>
>
> So i'm wondering what's the correct way to do this to prevent TS errors?
>
>
> Cheers.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to