Typescript Nested Functions In Javascript