jvcoach23
jvcoach23

Reputation: 3037

how to calling a javascript function from a typescript file

I have a file called general.js. In the file is a function

function fadeDivWrite(pString) {};

The typescript file is called Default.ts. I'm trying to call the fadeDivWrite function from general.js but it's not working. What i'm trying to use in the Default.ts file is

 var pText: string = "Test";
        declare function fadeDivWrite(pText): string;

The ts file won't compile with an red line under the declare. The error is (TS) Modifiers cannot appear here.

This is how I've seen it done in multipal places when doing searches so I'm missing something. Hoping someone can help out.

thanks shannon

Upvotes: 0

Views: 729

Answers (1)

Fenton
Fenton

Reputation: 250952

Just to clarify, the below should work - it certainly all passes a quick test on the TypeScript Playground.

declare function fadeDivWrite(text: string): string;

const pText: string = 'Test';
const result = fadeDivWrite(pText);

I have rewritten to avoid any confusion there might be between the type information and the actual variable pText.

Let me know if you still have an issue and include the error message if you have one.

Upvotes: 3

Related Questions