Visual Studio Code中的红色下划线

时间:2016-07-19 07:37:24

标签: typescript visual-studio-code

我有这些红色的sguiggles:

enter image description here

我正在创建带下划线的变量,如下所示:

import SearchFilterViewModel = SearchFilter.SearchFilterViewModel;
import SearchResultsViewModel = SearchResults.SearchResultsViewModel;
import AddProductViewModel = AddProduct.AddProductViewModel;
import Validator = Validation.Validator;

module Bindings {
    export class Binder {
        constructor() {
            searchFilterViewModel = new SearchFilterViewModel();
            searchFilterViewModel.errors = ko.validation.group(searchFilterViewModel);
            searchResultsViewModel = new SearchResultsViewModel();
            addProductViewModel = new AddProductViewModel();
            ko.applyBindings(searchFilterViewModel, $("#search-filter-page")[0]);
            ko.applyBindings(searchResultsViewModel, $("#search-results-page")[0]);
            ko.applyBindings(addProductViewModel, $("#add-product-page")[0]);
        }
    }
}

然后:

$(document).ready(function () {
    //apply bindings
    var binder = new Binder();
}

因此代码编译良好并且有效。如何摆脱那些红色下划线?

2 个答案:

答案 0 :(得分:2)

您必须声明属性(默认为public):

module Bindings {
    export class Binder {
        searchFilterViewModel:SearchFilterViewModel;
        constructor() {
            this.searchFilterViewModel = new SearchFilterViewModel();

答案 1 :(得分:1)

  

因此代码编译得很好并且有效。

仅仅因为代码生成有效的JavaScript 并不意味着没有编译错误

如果您通过tsc

运行项目,则很可能会看到错误

更多:https://basarat.gitbooks.io/typescript/content/docs/why-typescript.html