首页 > 解决方案 > 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>

当我键入fthen时fooAlert(text: any): void会列出两次(用any而不是string)。我猜我的解决方案中的 javascript 文件一次,打字稿文件一次。当我键入B然后BarNamespace列出。在我键入后BarNamespace.没有列出任何内容。我也有一个.js.map文件,但是当我将它添加到 js 文件旁边时,我看不到任何更改。

我做错了什么还是有办法改进 Visual Studio 2019 中的 IntelliSense 建议?该脚本在浏览器中运行,但至少对于可用的方法而言,拥有有用的 IntelliSense 建议会更容易、更安全。

标签: javascripttypescriptrazorvisual-studio-2019

解决方案


推荐阅读