title: properly declare local function angular2 + typescript
body: <p></p>
  
  <p>I am converting angular 1 to angular 2 (ionic 2), I created this provider to replace a service, but I get errors with the local functions.</p>
  
  <p><strong>How to declare a local function using angular2 and Typescript?</strong></p>
  
  <pre class="lang-ts prettyprint-override"><code>import { Injectable } from '@angular/core';
  
  
  @Injectable()
  export class PouchSeed {
  
      constructor() { }
  
      function normalizeDoc(doc, id) {
          function normalize(doc) {
              doc = angular.copy(doc);
              Object.keys(doc).forEach(function (prop) {
                  var type = typeof doc[prop];
                  if (type === 'object') {
                      doc[prop] = normalize(doc[prop]);
                  } else if (type === 'function') {
                      doc[prop] = doc[prop].toString();
                  }
              });
              return doc;
          }
  
          var output = normalize(doc);
          output._id = id || doc._id;
          output._rev = doc._rev;
          return output;
      }
      ....
      seed(db, designDocs, callback) {
          if (!db || !designDocs) {
              throw new TypeError('`db` and `design` are required');
          }
  
          var local = objMapValues(objMapKeys(designDocs, addDesign), normalizeDoc);
  
          var seedPromise = db.allDocs({include_docs: true, keys: Object.keys(local)})
  
                  .then(function (docs) {
  
                      var remote = {};
  
                      docs.rows.forEach(function (doc) {
                          if (doc.doc) {
                              remote[doc.key] = doc.doc;
                          }
                      });
  
                      var update = Object.keys(local).filter(function (key) {
                          if (!remote[key])
                              return true;
                          local[key]._rev = remote[key]._rev;
                          return !docEqual(local[key], remote[key]);
                      }).map(function (key) {
                          return local[key];
                      });
  
                      if (update.length &gt; 0) {
                          return db.bulkDocs({docs: update});
                      } else {
                          return Promise.resolve(false);
                      }
                  })
                  .then(function (result) {
                      if (typeof callback === 'function') {
                          callback(null, result);
                      }
                      return Promise.resolve(result);
                  })
                  .catch(function (err) {
                      if (typeof callback === 'function') {
                          callback(err, null);
                      }
                      console.log(err);
                      return Promise.reject(err);
                  });
  
          return seedPromise;
  
      };
  
  
  
  }
  </code></pre>
  
  <p>Errors:</p>
  
  <pre class="lang-ts prettyprint-override"><code>Typescript Error
  Unexpected token. A constructor, method, accessor, or property was expected.
  src/providers/pouch-seed.ts
      function normalizeDoc(doc, id) {
          function normalize(doc) {
  </code></pre>