0

We have a typescript class,which contains few methods. Sample example of the TypeScript class.

 export class AppointmentListComponent implements OnInit {
    editEvent(event: IEvent): void {
        this._router.navigate(['/appointments', event.id]);
    }
 }

We want to call editEvent method from another (.js) file. How can we achieve this.

ranakrunal9
  • 13,320
  • 3
  • 42
  • 43
user306905
  • 29
  • 7
  • 2
    possible duplicate: http://stackoverflow.com/questions/26427722/calling-properly-typescript-code-from-javascript – UnholySheep Dec 30 '16 at 09:20
  • Possible duplicate of [Calling properly TypeScript code from JavaScript](https://stackoverflow.com/questions/26427722/calling-properly-typescript-code-from-javascript) – Michael Freidgeim May 29 '17 at 12:48

1 Answers1

-2

If you are working with ES6 it's pretty simple. In typescript just use import "pathToJSModule"; and you are ready to use it. This is possible because JS is a valid Typescript.

If you are not working with ES6 you can use import * as foo from "pathToFile".

Peter Hrvola
  • 9
  • 1
  • 3
  • That's the wrong way round. OP wants to use TypeScript code from JavaScript, not JavaScript code from TypeScript – UnholySheep Dec 30 '16 at 09:40