import * as ko from "knockout"; declare module "knockout" { export module mapping { export type MappedObservable = { [P in keyof T]: T[P] extends ko.Observable | ko.ObservableArray ? T[P] : T[P] extends string | boolean | number | Date ? ko.Observable : T[P] extends Array ? ko.ObservableArray> : T[P] extends Function ? T[P] : T[P] extends object ? MappedObservable : T[P]; }; export type MappingOptions = MappingOptionsBase & MappingOptionsSpecific; export interface MappingOptionsBase { ignore?: (keyof T)[]; include?: (keyof T)[]; copy?: (keyof T)[]; observe?: (keyof T)[]; mappedProperties?: (keyof T)[]; deferEvaluation?: boolean; } export interface MappingOptionsProperty extends MappingOptionsBase { create?: (options: CreateOptions) => void; update?: (options: UpdateOptions) => void; key?: (data: T) => any; } export type MappingOptionsSpecific = { [P in keyof T]?: T[P] extends Array ? MappingOptionsProperty : MappingOptionsProperty; }; export interface CreateOptions { data: T; parent: any; } export interface UpdateOptions { data: T; parent: any; target: any; observable?: ko.Observable; } export interface VisitModelOptions { visitedObjects?: any; parentName?: string; ignore?: string[]; copy?: string[]; include?: string[]; } /** * Checks if an object was created using `knockout.mapping`. * @param viewModel View model object to be checked. */ export function isMapped(viewModel: any): boolean; /** * Updates target observable with value from the source. * * @param source Plain JavaScript value to be mapped. * @param target Observable to be updated. */ export function fromJS(source: string, target: ko.Observable): ko.Observable; /** * Creates an observable wrapping source's value. * If 'target' is supplied, instead, target observable is updated. * * @param source Plain JavaScript value to be mapped. * @param options The mapping options. * @param target Observable to be updated. */ export function fromJS(source: string, inputOptions?: MappingOptions, target?: ko.Observable): ko.Observable; /** * Updates target observable with value from the source. * * @param source Plain JavaScript value to be mapped. * @param target Observable to be updated. */ export function fromJS(source: number, target: ko.Observable): ko.Observable; /** * Creates an observable wrapping source's value. * If 'target' is supplied, instead, target observable is updated. * * @param source Plain JavaScript value to be mapped. * @param options The mapping options. * @param target Observable to be updated. */ export function fromJS(source: number, inputOptions?: MappingOptions, target?: ko.Observable): ko.Observable; /** * Updates target observable with value from the source. * * @param source Plain JavaScript value to be mapped. * @param target Observable to be updated. */ export function fromJS(source: boolean, target: ko.Observable): ko.Observable; /** * Creates an observable wrapping source's value. * If 'target' is supplied, instead, target observable is updated. * * @param source Plain JavaScript value to be mapped. * @param options The mapping options. * @param target Observable to be updated. */ export function fromJS(source: boolean, inputOptions?: MappingOptions, target?: ko.Observable): ko.Observable; /** * Creates a view model object with observable properties for each of the properties on the source. * * @param source Plain JavaScript array to be mapped. */ export function fromJS(source: SourceT[]): ko.ObservableArray>; /** * Creates a view model object with observable properties for each of the properties on the source. * * @param source Plain JavaScript array to be mapped. * @param inputOptions The mappings options with no properties. */ export function fromJS(source: SourceT[], inputOptions: {}): ko.ObservableArray>; /** * Creates a view model object with observable properties for each of the properties on the source. * If 'target' is supplied, instead, target's observable properties are updated. * * @param source Plain JavaScript array to be mapped. * @param options The mapping options. * @param target View model object previously mapped to be updated. */ export function fromJS(source: SourceT[], inputOptions: MappingOptions, target?: ko.ObservableArray): ko.ObservableArray; /** * Updates target's observable properties with those of the sources. * * @param source Plain JavaScript array to be mapped. * @param target View model object previously mapped to be updated. */ export function fromJS(source: SourceT[], target: ko.ObservableArray): ko.ObservableArray; /** * Creates a view model object with observable properties for each of the properties on the source. * * @param source Plain JavaScript object to be mapped. */ export function fromJS(source: SourceT): MappedObservable; /** * Creates a view model object with observable properties for each of the properties on the source. * * @param source Plain JavaScript object to be mapped. * @param inputOptions The mappings options with no properties. */ export function fromJS(source: SourceT, inputOptions: {}): MappedObservable; /** * Creates a view model object with observable properties for each of the properties on the source. * If 'target' is supplied, instead, target's observable properties are updated. * * @param source Plain JavaScript object to be mapped. * @param options The mapping options. * @param target View model object previously mapped to be updated. */ export function fromJS(source: SourceT, inputOptions: MappingOptions, target?: MappedT): MappedT; /** * Updates target's observable properties with those of the sources. * * @param source Plain JavaScript object to be mapped. * @param target View model object previously mapped to be updated. */ export function fromJS(source: SourceT, target: MappedT): MappedT; /** * Creates a view model object with observable properties for each of the properties on the source. * If 'target' is supplied, instead, target's observable properties are updated. * * @param jsonString JSON of a JavaScript object to be mapped. * @param options Options on mapping behavior. * @param target View model object previosly mapped to be updated. */ export function fromJSON(jsonString: string, inputOptions?: MappingOptions, target?: MappedT): MappedT; /** * Updates target's observable properties with those of the sources. * * @param jsonString JSON of a JavaScript object to be mapped. * @param target View model object previously mapped to be updated. */ export function fromJSON(jsonString: string, target: MappedT): MappedT; /** * Creates an unmapped object containing only the properties of the mapped object that were part of your original JS object. * * @param rootObject Object with observables to be converted. * @param options The mapping options */ export function toJS(rootObject: MappedObservable, options?: MappingOptions): T; /** * Creates an unmapped object containing only the properties of the mapped object. * * @param rootObject Object with observables to be converted. * @param options The mapping options */ export function toJS(rootObject: MappedT, options?: MappingOptions): SourceT; /** * Creates an unmapped object containing only the properties of the mapped object that were part of your original JS object. * Stringify the result. * * @param rootObject Object with observables to be converted. * @param options The mapping options. * @param replacer Same as JSON.stringify * @param space Sam as JSON.stringify */ export function toJSON(rootObject: SourceT, options?: MappingOptions, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string; /** Get the default mapping options. */ export function defaultOptions(): MappingOptions; /** * Sets the default mapping options. * * @param options The new default options. */ export function defaultOptions(options: MappingOptions): void; /** Undocumented. Reset Mapping default options to the original ones. */ export function resetDefaultOptions(): void; /** * Undocumented. Custom implementation of JavaScript's typeof. * * @param x Object to check type. */ export function getType(x: any): string; /** * Undocumented. Visit an object and executes callback on each properties. * * @param rootObject The root object to visit. * @param callback The callback which is executed on each properties. * @param options The options for the visiting. */ export function visitModel(rootObject: Object, callback: (propertyValue: any, parentName: string) => any, options?: VisitModelOptions): T; } export interface ObservableArrayFunctions { mappedCreate(item: T): T; mappedRemove(item: T): T[]; mappedRemove(removeFunction: (item: T) => boolean): T[]; mappedRemoveAll(): T[]; mappedRemoveAll(items: T[]): T[]; mappedDestroy(item: T): void; mappedDestroy(destroyFunction: (item: T) => boolean): void; mappedDestroyAll(): void; mappedDestroyAll(items: T[]): void; } } export = ko.mapping;