Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
63
rated 0 times [  65] [ 2]  / answers: 1 / hits: 30487  / 12 Years ago, fri, october 26, 2012, 12:00:00

I have the following function in a file:



function alertWin(title, message) {
.......
.......
}


In another typescript file I have:



function mvcOnFailure(message) {
use strict;
alertWin(Internal Application Error, message);
}


I am getting an error saying alertwin does not exist in the current scope.



Is the way to solve this for me to define this function in another file and then reference that? If so then what would the definition look like?


More From » typescript

 Answers
67

You can do this (assuming title and message are both supposed to be strings):



interface alertWinInterface{
(title:string, message: string):any;
}

declare var alertWin: alertWinInterface;


You could put this in the same file, or put it in a separate ambient definitions file (.d.ts) which you import:



/// <reference path=myDefinitions.d.ts />


Or, you could just import the other file that has the actual function definition, but you won't get static typing support.


[#82333] Thursday, October 25, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
raymondd

Total Points: 620
Total Questions: 112
Total Answers: 94

Location: Namibia
Member since Mon, Feb 21, 2022
2 Years ago
raymondd questions
Thu, Apr 22, 21, 00:00, 3 Years ago
Thu, Jul 9, 20, 00:00, 4 Years ago
Thu, Apr 9, 20, 00:00, 4 Years ago
Thu, Jul 25, 19, 00:00, 5 Years ago
;