Currently in the process of migrating from Angular 1 to 2, encountering a situation with nested functions in JavaScript:
function normalizeDoc(doc, id) {
function normalize(doc){...
After removing the "function" keyword, TypeScript errors have started to appear.
import { Injectable } from '@angular/core';
@Injectable()
export class PouchSeed {
constructor(
) {
}
normalizeDoc(doc, id) {
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;
};
The following errors are being encountered:
Typescript Error
';' expected.
src/providers/pouch-seed.ts
normalizeDoc(doc, id) {
normalize(doc) {
doc = angular.copy(doc);
Typescript Error
Cannot find name 'normalize'.
src/providers/pouch-seed.ts
normalizeDoc(doc, id) {
normalize(doc) {
Typescript Error
Cannot find name 'angular'.
src/providers/pouch-seed.ts
normalize(doc) {
doc = angular.copy(doc);
Questioning whether nesting methods like this is appropriate and seeking clarity on the reason behind the ";" error?