javascript - Visual Studio 2019 MVC 视图中的 Typescript/Javascript Intellisense
问题描述
我有这个打字稿代码:
function fooAlert(text: string): void {
alert(text);
}
namespace BarNamespace {
export function barAlert(text: string): void {
alert(text);
}
export class BarEmpty {
}
}
使用 gulp 任务将 typescript 代码转换为 javascript:
function fooAlert(text) {
alert(text);
}
var BarNamespace;
(function(BarNamespace) {
function barAlert(text) {
alert(text);
}
BarNamespace.barAlert = barAlert;
var BarEmpty = function() {
function BarEmpty() {}
return BarEmpty;
}();
BarNamespace.BarEmpty = BarEmpty;
})(BarNamespace || (BarNamespace = {}));
问题是,Visual Studio 2019 中的 IntelliSense 在 Razor 标记中不起作用,正如我所期望的那样。例如,我有这个 asp.net MVC Core 3.1 视图(.cshtml):
<!DOCTYPE html>
<html lang="en">
<head>
<script src="~/Site.js" asp-append-version="true"></script>
</head>
<body>
<script>
fooAlert("foo"); // IntelliSense match after typing f
BarNamespace.barAlert("bar"); // IntelliSense match after typing B for BarNamespace but not for .barAlert
</script>
</body>
</html>
当我键入f
then时fooAlert(text: any): void
会列出两次(用any
而不是string
)。我猜我的解决方案中的 javascript 文件一次,打字稿文件一次。当我键入B
然后BarNamespace
列出。在我键入后BarNamespace
,.
没有列出任何内容。我也有一个.js.map
文件,但是当我将它添加到 js 文件旁边时,我看不到任何更改。
我做错了什么还是有办法改进 Visual Studio 2019 中的 IntelliSense 建议?该脚本在浏览器中运行,但至少对于可用的方法而言,拥有有用的 IntelliSense 建议会更容易、更安全。
解决方案
推荐阅读
- sqlite - 在可执行 jar 中包含 Sqlite 数据库
- javascript - 为什么我的 onclick 按钮在页面加载时调用了一个函数?
- php - 无法将 PHP OpenSSL IV 转换为 Node.JS
- r - dplyr 可以将合并列中的值加在一起吗?
- google-apps-script - Google App Script - 从 pdf URL 和电子邮件地址列表中授予一对一查看权限
- git - 无法推送分支 A,因为未能推送分支 B、C、D 上的引用,
- css - 将滑出表单放置在屏幕的右边缘
- javascript - 创建一个可重用的 Chartjs 函数
- r - 在R中的cowplot包中对齐2行中的垂直3个图
- javascript - TypeError:未定义不是对象(评估“app.firestore”)