Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Knockout JS Decleration file for Typescript (just a starter mind ya)
//Interface started from http://stackoverflow.com/questions/12689716/typescript-with-knockoutjs
interface ObservableNumber {
(newValue: number): ObservableNumber; // Set the value of the observable
(): number; // Get the value of the observable
subscribe: (newValue: number) => void; // Subscribe to get informed when the observable changes
valueHasMutated(): void;
valueWillMutate(): void;
}
interface ObservableString {
(newValue: string): ObservableString; // Set the value of the observable
(): string; // Get the value of the observable
subscribe: (newValue: string) => void; // Subscribe to get informed when the observable changes
valueHasMutated(): void;
valueWillMutate(): void;
}
interface ObservableBool {
(newValue: bool): ObservableBool; // Set the value of the observable
(): bool; // Get the value of the observable
subscribe: (newValue: bool) => void; // Subscribe to get informed when the observable changes
valueHasMutated(): void;
valueWillMutate(): void;
}
interface ObservableAny {
(newValue: any): ObservableAny; // Set the value of the observable
(): any; // Get the value of the observable
subscribe: (newValue: any) => void; // Subscribe to get informed when the observable changes
valueHasMutated(): void;
valueWillMutate(): void;
}
interface observableArrayAny {
(newValue: any[]): observableArrayAny;
(): any[];
subscribe: (newValue: any[]) => void;
indexOf(item: any): number;
replace(oldItem: any, newItem: any): void;
slice(start: number, count: number): any[];
push(item: any): void;
pop(): any;
unshift(item: any): void;
shift(): any;
reverse(): void;
sort(): void;
sort(func: (left: any, right: any) => number): void;
splice(start: number, count: number): any[];
remove(func: (item: any) => bool): void;
remove(item: any): void;
removeAll(): void;
removeAll(items: any[]): void;
destroy(func: (item: any) => bool): void;
destroy(item: any): void;
destroyAll(): void;
destroyAll(items: any[]): void;
valueHasMutated(): void;
valueWillMutate(): void;
}
class Knockout {
observable: {
(value: number): ObservableNumber;
(value: string): ObservableString;
(value: bool): ObservableBool;
(value: any): ObservableAny;
};
observableArray: observableArrayAny;
}
declare var ko: Knockout;

Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment