Knockout extenders

67 views Asked by At

I have the following extender below and I am trying to use it in typescript and I'm getting the error listed. I have searched through so alot of documentation and this seems to be the way it should be done. I should note I am using the extender in multiple different files.

What do I do to fix this?

Any advise would be appreciated, thank you!

declare global {
interface KnockoutExtenders {
        uppercase(target: any, option: boolean): ko.Observable<any>;
}
}
....
ko.extenders.uppercase = function (target, option) {

        var result = ko.pureComputed({
            read: target,
            write: function (newValue) {

                var current = target();
                var valueToWrite = newValue.toUpperCase()

                if (valueToWrite !== current) {
                    target(valueToWrite);
                } else {
                    //if the rounded value is the same, but a different value was written, force a notification for the current field
                    if (newValue !== current) {
                        target.notifySubscribers(valueToWrite);
                    }
                }

            }
        }).extend({ notify: 'always' });

        result(target());
        return result;

    };

Error:

error TS2769: No overload matches this call.
  Overload 1 of 2, '(requestedExtenders: ObservableExtenderOptions<string>): Observable<string>', gave the following error.
    Argument of type '{ uppercase: boolean; }' is not assignable to parameter of type 'ObservableExtenderOptions<string>'.
      Object literal may only specify known properties, and 'uppercase' does not exist in type 'ObservableExtenderOptions<string>'.
  Overload 2 of 2, '(requestedExtenders: ObservableExtenderOptions<string>): Observable<string>', gave the following error.
    Argument of type '{ uppercase: boolean; }' is not assignable to parameter of type 'ObservableExtenderOptions<string>'.
      Object literal may only specify known properties, and 'uppercase' does not exist in type 'ObservableExtenderOptions<string>'.

165         this.itemNumber = ko.observable('').extend({ uppercase: true });
0

There are 0 answers