3

how to use JavaScript file(function) in typescript.

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

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

1

2 Answers 2

2

A very simple solution:

declare var Abc: any;
Abc();
Sign up to request clarification or add additional context in comments.

1 Comment

Using this defeats the purpose of using typescript. As soon as you use any, all bets are off an you have no type safety.
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();

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.