0

I was wondering if there is any way to make a generic variable without use the KnockoutObservableAny

I would like to do something like KnockoutObservable<SomeType>() = new Sometype()

I know this is possible for arrays

KnockoutObservableArray with typed elements in TypeScript

but I couldn't find a way to do this for regular variables.

Community
  • 1
  • 1
James
  • 557
  • 1
  • 12
  • 29
  • So are you using typescript or javascript? That doesn't apply to javascript... – Jeff Mercado Jun 07 '14 at 01:13
  • 2
    What type definitions are you using? Self made? The one on [DefinitelyTyped](https://github.com/borisyankov/DefinitelyTyped/blob/master/knockout/knockout.d.ts) appears to have all you would need. – Jeff Mercado Jun 07 '14 at 01:20

1 Answers1

1

couple examples:

interface Chicken {
   eggs: number;
}

var x: KnockoutObservable<string> = ko.observable(''),
    y: KnockoutObservable<Chicken> = ko.observable(),
    z: KnockoutObservable<Chicken> = ko.observable({ eggs: 6 });
Jeremy Danyow
  • 26,470
  • 12
  • 87
  • 133