EspoCRM – Open Source CRM Application
PHP calendarcontactscrmcrm-platformcrm-systemcustomer-portalcustomer-supportcustomizabledocumentsemail-marketingkanbanleadsopen-sourcephpplatformsales-automationsingle-page-applicationsupport
Type fixes
Yurii204b01653044
diff --git a/client/src/model-factory.ts b/client/src/model-factory.tsindex 6863147854..1b8f63ef5a 100644--- a/client/src/model-factory.ts+++ b/client/src/model-factory.ts@@ -30,6 +30,7 @@import Metadata from 'metadata';import Model from 'model';+import loader/*** A model factory.diff --git a/client/src/model.ts b/client/src/model.tsindex f20ff242ff..ff0369d54f 100644--- a/client/src/model.ts+++ b/client/src/model.ts@@ -33,6 +33,7 @@ import _ from 'underscore';import DefaultValueProvider from 'helpers/model/default-value-provider';import {onModelChange, onSync} from 'util/event';import {AjaxPromise} from 'util/ajax';+import Ajax from 'ajax';/*** When attributes have changed.@@ -145,7 +146,7 @@ export default class Model<T extends Record<string, unknown> = Record<string, an*/public collection: Collection | undefined- private changed: Partial<T>+ private changed: Partial<T> | Record<string, null>private _previousAttributes: null | Partial<T>/**@@ -221,12 +222,13 @@ export default class Model<T extends Record<string, unknown> = Record<string, an'read': 'GET',};- const httpMethod = methodMap[method];-- if (!httpMethod) {+ if (!(method in methodMap)) {throw new Error(`Bad request method '${method}'.`);}+ const httpMethod = methodMap[method as keyof typeof methodMap] as+ 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'OPTIONS';+options = options || {};const url = this.composeSyncUrl();@@ -252,14 +254,16 @@ export default class Model<T extends Record<string, unknown> = Record<string, anconst stringData = data ? JSON.stringify(data) : null;const ajaxPromise = !options.bypassRequest ?- Espo.Ajax.request(url, httpMethod, stringData, options) :+ Ajax.request(url, httpMethod, stringData, options) :Promise.resolve();- options.xhr = ajaxPromise.xhr;+ if (ajaxPromise instanceof AjaxPromise) {+ options.xhr = ajaxPromise.xhr;+ }model.trigger('request', url, httpMethod, data, ajaxPromise, options);- return ajaxPromise;+ return ajaxPromise as AjaxPromise;}// noinspection JSValidateJSDoc@@ -275,7 +279,7 @@ export default class Model<T extends Record<string, unknown> = Record<string, anset(attribute: keyof T,value: any,- options: {silent: boolean} & Record<string, any> = undefined+ options?: {silent: boolean} & Record<string, any>,): this {if (attribute == null) {@@ -301,17 +305,35 @@ export default class Model<T extends Record<string, unknown> = Record<string, an* @param attributes* @param [options] Options. `silent` won't trigger a `change` event.* `sync` can be used to emulate syncing.- * @return {this}* @fires Model#change Unless `{silent: true}`.- * @copyright Credits to Backbone.js.*/setMultiple(attributes: Partial<T>,- options: {+ options?: {+ silent?: boolean,+ sync?: boolean,+ } & Record<string, any>,+ ): this {++ return this._setMultipleInternal(attributes, options);+ }++ // noinspection JSValidateJSDoc+ /**+ * Set attributes values.+ *+ * @param attributes+ * @param [options]+ * @fires Model#change Unless `{silent: true}`.+ * @copyright Credits to Backbone.js.+ */+ private _setMultipleInternal(+ attributes: Partial<T> | Record<string, null>,+ options?: {silent?: boolean,unset?: boolean,sync?: boolean,- } & Record<string, any> = undefined,+ } & Record<string, any>,): this {if (this.idAttribute in attributes) {@@ -338,9 +360,9 @@ export default class Model<T extends Record<string, unknown> = Record<string, anthis.changed = {};}- const current = this.attributes;- const changed = this.changed;- const previous = this._previousAttributes;+ const current = this.attributes as Record<string, any>;+ const changed = this.changed as Record<string, any>;+ const previous = this._previousAttributes as Record<string, any>;for (const attribute in attributes) {const value = attributes[attribute];@@ -412,10 +434,10 @@ export default class Model<T extends Record<string, unknown> = Record<string, anoptions = {...options, unset: true};- const attributes = {} as Partial<T>;- attributes[attribute] = null;+ const attributes = {} as Record<string, any>;+ attributes[attribute as string] = null;- return this.setMultiple(attributes, options);+ return this._setMultipleInternal(attributes, options);}/**@@ -423,7 +445,7 @@ export default class Model<T extends Record<string, unknown> = Record<string, an** @param attribute An attribute name.*/- get<K extends keyof T>(attribute: K): T[K] {+ get<K extends keyof T>(attribute: K): T[K] | undefined {if (attribute === this.idAttribute && this.id) {return this.id as T[K];}@@ -488,14 +510,14 @@ export default class Model<T extends Record<string, unknown> = Record<string, an* Get changed attribute values. To be called only within a 'change' event handler.*/changedAttributes(): Partial<T> {- return this.hasChanged() ? _.clone(this.changed) : {};+ return this.hasChanged() ? _.clone(this.changed as Partial<T>) : {};}/*** Get previous attributes. To be called only within a 'change' event handler.*/previousAttributes(): Partial<T> {- return _.clone(this._previousAttributes);+ return _.clone(this._previousAttributes ?? {});}/**@@ -795,7 +817,7 @@ export default class Model<T extends Record<string, unknown> = Record<string, an* Populate default values.*/populateDefaults() {- let defaultHash = {};+ let defaultHash = {} as Record<string, unknown>;const fieldDefs = this.defs.fields;@@ -825,7 +847,7 @@ export default class Model<T extends Record<string, unknown> = Record<string, an}}- this.setMultiple(defaultHash, {silent: true});+ this.setMultiple(defaultHash as Partial<T>, {silent: true});}/**@@ -873,7 +895,11 @@ export default class Model<T extends Record<string, unknown> = Record<string, anthrow new Error('Bad related options');}- const type = this.defs.links[link].type;+ if (!model.id) {+ throw new Error('Bad related model. No ID.');+ }++ const type = this.defs.links?.[link]?.type;switch (type) {case 'belongsToParent':@@ -893,7 +919,7 @@ export default class Model<T extends Record<string, unknown> = Record<string, anconst ids = [];ids.push(model.id);- const names = {};+ const names = {} as Record<string, any>;names[model.id] = model.get('name');@@ -1054,7 +1080,7 @@ export default class Model<T extends Record<string, unknown> = Record<string, an* @param {string} field A field name.*/hasField(field: string): boolean {- return ('fields' in this.defs) && (field in this.defs.fields);+ return ('fields' in this.defs) && (field in (this.defs as any).fields);}/**@@ -1063,7 +1089,7 @@ export default class Model<T extends Record<string, unknown> = Record<string, an* @param {string} link A link name.*/hasLink(link: string): boolean {- return ('links' in this.defs) && (link in this.defs.links);+ return ('links' in this.defs) && (link in (this.defs as any).links);}/**@@ -1083,8 +1109,8 @@ export default class Model<T extends Record<string, unknown> = Record<string, an/*** Get an entity type.*/- getEntityType(): string {- return this.name;+ getEntityType(): string | null {+ return this.entityType;}/**diff --git a/client/src/view.ts b/client/src/view.tsindex 9555e0a922..b1a4d2d755 100644--- a/client/src/view.ts+++ b/client/src/view.ts@@ -119,7 +119,7 @@ export default class View<S extends ViewSchema = ViewSchema> extends BullView<S[this.events[fullAction] = e => {// noinspection JSUnresolvedReference- handler.call(this, e.originalEvent, e.currentTarget);+ handler.call(this, e.originalEvent as MouseEvent, e.currentTarget as HTMLElement);};}@@ -150,23 +150,23 @@ export default class View<S extends ViewSchema = ViewSchema> extends BullView<S[return;}- timeout = timeout || 2000;+ let timeoutInternal : number | undefined = timeout || 2000;if (!type) {- timeout = void 0;+ timeoutInternal = undefined;}const text = this.getLanguage().translate(label, 'labels', scope || undefined);// @ts-ignore- Ui.notify(text, type, timeout);+ Ui.notify(text, type, timeoutInternal);}/*** Get a view-helper.*/getHelper(): import('view-helper').default {- return this._helper;+ return this._helper as import('view-helper').default;}/**diff --git a/package-lock.json b/package-lock.jsonindex efee776350..4792fad58a 100644--- a/package-lock.json+++ b/package-lock.json@@ -22,7 +22,7 @@"bootstrap": "github:yurikuzn/espo-bootstrap#0.1.2","bootstrap-colorpicker": "^2.5.2","bootstrap-datepicker": "^1.9.0",- "bullbone": "github:espocrm/bullbone#1.4.0",+ "bullbone": "github:espocrm/bullbone#1.4.1","cronstrue": "^1.114.0","cropper": "^0.7.9","devbridge-autocomplete": "^1.4.11",@@ -3435,8 +3435,8 @@}},"node_modules/bullbone": {- "version": "1.4.0",- "resolved": "git+ssh://[email protected]/espocrm/bullbone.git#de477aea3dae34a5f943f5a6b1a39968f7b18077",+ "version": "1.4.1",+ "resolved": "git+ssh://[email protected]/espocrm/bullbone.git#ee78dd11f13a5c29465f218bd2852dfd72a9ceed","license": "AGPL","dependencies": {"snabbdom": "^3.6.3"@@ -10989,8 +10989,8 @@"dev": true},"bullbone": {- "version": "git+ssh://[email protected]/espocrm/bullbone.git#de477aea3dae34a5f943f5a6b1a39968f7b18077",- "from": "bullbone@github:espocrm/bullbone#1.4.0",+ "version": "git+ssh://[email protected]/espocrm/bullbone.git#ee78dd11f13a5c29465f218bd2852dfd72a9ceed",+ "from": "bullbone@github:espocrm/bullbone#1.4.1","requires": {"snabbdom": "^3.6.3"}diff --git a/package.json b/package.jsonindex 240617008b..c12179d299 100644--- a/package.json+++ b/package.json@@ -69,7 +69,7 @@"bootstrap": "github:yurikuzn/espo-bootstrap#0.1.2","bootstrap-colorpicker": "^2.5.2","bootstrap-datepicker": "^1.9.0",- "bullbone": "github:espocrm/bullbone#1.4.0",+ "bullbone": "github:espocrm/bullbone#1.4.1","cronstrue": "^1.114.0","cropper": "^0.7.9","devbridge-autocomplete": "^1.4.11",