Reputation: 1890
Now that Knockout 3.5.0 has been released, I am having problems getting Knockout validation to compile with the new type defintion structure that is supplied with Knockout 3.5.0.
I was able to get Knockout validation to properly integrate somewhat with the new type defintion file from 3.5.0 by doing the following things:
first: added an import at the top of the knockout valiation index.d.ts file:
import { Observable, ObservableArray, Computed, Static, SubscribableFunctions, ObservableExtenderOptions } from "knockout";
second: changed KnockoutObservable, KnockoutComputed and KnockoutObservableArray references to Observable, Computed and ObservableArray
third: wrapped the extensions of the Knockout interfaces in a declare module "knockout" statement: export interface KnockoutValidationRuleDefinitions extends ObservableExtenderOptions { }
declare module "knockout" {
interface Static {
validation: KnockoutValidationStatic;
validatedObservable<T>(initialValue?: T): Observable<T>;
applyBindingsWithValidation(viewModel: any, rootNode?: any, options?: KnockoutValidationConfiguration): void;
}
export interface SubscribableFunctions<T> {
isValid: Computed<boolean>;
isValidating: Observable<boolean>;
rules: ObservableArray<KnockoutValidationRule>;
isModified: Observable<boolean>;
error: Computed<string>;
setError(error: string): void;
clearError(): void;
}
}
This works great, but now I am getting compilation errors on all the .extend calls that tag the observables with requirements. For instance:
this.settings.name.extend({ required: true });
gives an error: No overload matches this call.
TS2769 TypeScript (TS) No overload matches this call. Overload 1 of 2,, gave the following error. Argument of type is not assignable to parameter of type. Object literal may only specify known properties, and does not exist in type. Overload 2 of 2,, gave the following error. Argument of type is not assignable to parameter of type. Object literal may only specify known properties, and does not exist in type.
Any suggestions on how to rework the knockout validation index.d.ts file to properly extend the extend method of Knockout?
For reference the index.d.ts file for knockout validation is here.
Upvotes: 2
Views: 918
Reputation: 1890
A kind sole on Github posted a PR on Knockout.validation that includes a new knockout.validation.d.ts file that uses the new 3.5.0 style typings.
His PR hasn't been accepted yet, but you can find the file here
Hopefully it will be pulled into knockout-validation and a new npm package will be created. For now, if you run into this issue, you can grab that typings file and use it directly. Thats what I plan to do as soon as I can get my windows build machine back up and running. Damn windows!
Upvotes: 1