-2

I have a function in my TypeScript file:

public test(): string[] {
    return new Array("Mary", "Tom", "Jack", "Jill");
}

How do I call this function from JavaScript?

Jack Bashford
  • 43,180
  • 11
  • 50
  • 79
srikar kulkarni
  • 630
  • 1
  • 6
  • 16

2 Answers2

3

TypeScript files are source files that are not run directly, they are transpiled to JavaScript before they can be run. Normally project using TypeScript have some sort of build pipeline setup using something like Webpack, you cannot just use a TypeScript file directly with a JavaScrpt project.

Adrian Brand
  • 20,384
  • 4
  • 39
  • 60
1

TypeScript is compiled to JavaScript before anything else happens - so once it's compiled, you call it later in your project just like you would any other function:

test();
Jack Bashford
  • 43,180
  • 11
  • 50
  • 79
  • actually i guess i have to import the .js file which is a compiled .ts file but writing that in script part of html is really not working – srikar kulkarni Jul 01 '19 at 11:28