我有这些红色的sguiggles:
我正在创建带下划线的变量,如下所示:
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();
}
因此代码编译良好并且有效。如何摆脱那些红色下划线?
答案 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