Correct way to fix knockout typescript compiler error after upgrading to 0.9.5

knockout.js, typescript

Solution

It seems `ko.observable` and `ko.observableArray` should be updated to be generic so:

prop: KnockoutObservable<string> = ko.observable<string>();
prop: KnockoutObservableArray<string> = ko.observableArray<string>(); 

Problem

Just upgraded typescript from 0.9.1.1 to 0.9.5 and am seeing compiler errors with lines like this: ``` prop: KnockoutObservable<string> = ko.observable(); ``` The error is: ``` Cannot convert KnockoutObservable<{}> to KnockoutObservable<string> ``` I read about the breaking changes, but I am wondering, what is the correct fix for this? This seems to work, and I think it's functionally correct, at least if/until knockout.d.ts is changed to accommodate the new compiler changes: ``` prop: KnockoutObservable<string> = ko.observable(undefined); ``` However, I still can't find a fix for observableArrays: ``` prop: KnockoutObservableArray<string> = ko.observableArray(undefined); // compiler error prop: KnockoutObservableArray<string> = ko.observableArray([]); // compiler error ``` Update: Just found out this works for observableArray. Need to cast undefined: ``` prop = ko.observableArray(<string[]>undefined); // builds ``` Because of the casting in the function argument, the type of the array is cast correctly.

Original source