0

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

2
  • declare goes in the declaration file general.d.ts. Use import * as general from './path/to/general'. Call the method as general.fadeDivWrite() in your ts file. Commented Nov 7, 2018 at 14:07
  • So just to be clear your problem is with the transpiler? So you don't know if the code itself works should it transpile? Commented Nov 7, 2018 at 14:07

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

thanks for the response. So i put that in my ts file. Now fadeDivWrite has the red line under it telling me "Overload signatures must all be ambient or non-ambient. Would sure appreciate it if your willing to continue helping.
Ah - it is likely that you have inadvertently included the function in the compilation, as well as the ambient declaration. Are you sure it isn't either a) in a TypeScript file already, or b) are you including JavaScript files in your compilation, so the general.js is part of the compile?
that was it.. has included a reference to the java script file. I up voted your answer. thanks much

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.