Skip to content
Dmitry Panyushkin edited this page Oct 10, 2017 · 1 revision

Typings

@types/knockout

npm install --save-dev @types/knockout

This package provides some type definitions in global namespace.

let name: KnockoutObservable = ko.observable("John");
let upper: KnockoutComputed = ko.computed(() => name().toUpperCase());

Decorators

There are two different libraries for decorators support:

These plugins will allow you to be away with parentheses.

@component("person-view", `
  <div>Name: <span data-bind="text: fullName"></span></div>
  <div>Age: <span data-bind="text: age"></span></div>
`)
class PersonView {
  @observable firstName = "John";
  @observable lastName = "Doe";
  @observable age = 18;
  
  @computed get fullName() {
    return this.firstName + " " + this.lastName;
  }
}

Clone this wiki locally