How can I make TypeScript aware that the Variable is defined in the cshtml file? Can I add a reference inside the ts file?
1 Answer
You can do this in a TypeScript file or a .d.ts file:
declare var fromMvc: string;
This doesn't produce any code, but it makes the compiler aware that a variable with the name "fromMvc" exists. After declaring that you can use it like a normal variable.
2 Comments
Revious
Thanks. I've also found that if the variable is defined in another JS it's possible to write: /// <reference path="../typings/jquery/jquery.d.ts" />
Dick van den Brink
You are right, when it is defined somewhere else you can use the reference tag. When you are in Visual Studio and the .d.ts is part of your project (with TypeScriptCompile as build action) you don't need the references tag (normally, you might need it for ordering when using single output as an option)