3

how to use JavaScript file(function) in typescript.

//abc.js
function Abc(){
alert();
}

//test.ts now how to use Abc() function in typescript

Rob
  • 26,989
  • 16
  • 82
  • 98
Prabin Thapa
  • 31
  • 1
  • 2
  • 2
    Possible duplicate of [How use an external non-typescript library from typescript without .d.ts?](http://stackoverflow.com/questions/27417107/how-use-an-external-non-typescript-library-from-typescript-without-d-ts) – Rob May 16 '17 at 06:26

2 Answers2

2

A very simple solution:

declare var Abc: any;
Abc();
andrean
  • 107
  • 12
  • Using this defeats the purpose of using typescript. As soon as you use any, all bets are off an you have no type safety. – Gerrit0 May 16 '17 at 12:55
1

A simple solution:

lib.ts

export default class Lib {
    public Abc() {
        alert();
    }
}

main.ts

import Lib from "./lib"

var lib = new Lib();
lib.Abc();
Aurélien Gasser
  • 3,043
  • 1
  • 20
  • 25
  • 1
    that is not solution. where is .js file my question is how to import js file in .ts file and how to use .js file function. – Prabin Thapa May 17 '17 at 05:08