0

The type definition for the ngstorage library is as follows:

import * as angular from 'angular';

declare module 'angular' {
  export namespace storage {

    export interface IStorageService {
      //interface definition
    }

    export interface IStorageProvider extends angular.IServiceProvider {
      //interface definition
    }
  }
}

Three questions:

  1. What exactly happens when the already-existing module 'angular' is declared again, as happens on line 3 of this example?
  2. What does it mean to export a namespace inside a module definition export namespace storage?
  3. How do I import IStorageService into my .ts files? Nothing I've tried so far works.

    import { IStorageService } from 'ngstorage'

    import { IStorageService } from 'angular.storage'

    or just directly refer to IStorageService like so:

    angular.storage.IStorageService

1 Answer 1

1

It's called Module Augmentation, and it's a way to add definitions to existing modules.
In this case, when you are importing the file that you posted it will add the new definitions to the angular module, just like the js file does at runtime.

You should be able to import it like so:

import * as angular from 'ngstorage';

let a: angular.storage.IStorageService;
...

Edit

Try:

import * as angular from 'angular';
import 'ngstorage';

let a: angular.storage.IStorageService;
Sign up to request clarification or add additional context in comments.

3 Comments

What's the significance of using the export keyword inside the module? Wouldn't just declaring the namespace add it to the module and make it available? Also, using angular.storage.IStorageService gives me the error "error TS2305: Module 'angular' has no exported member 'storage'."
Where did you get the .d.ts file from?

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.