diff --git a/libs/horizon/src/dom/DOMPropertiesHandler/DOMPropertiesHandler.ts b/libs/horizon/src/dom/DOMPropertiesHandler/DOMPropertiesHandler.ts index 156f9710..3d5f7d36 100644 --- a/libs/horizon/src/dom/DOMPropertiesHandler/DOMPropertiesHandler.ts +++ b/libs/horizon/src/dom/DOMPropertiesHandler/DOMPropertiesHandler.ts @@ -1,12 +1,12 @@ import { allDelegatedHorizonEvents, } from '../../event/EventCollection'; -import {updateCommonProp} from './UpdateCommonProp'; -import {setStyles} from './StyleHandler'; +import { updateCommonProp } from './UpdateCommonProp'; +import { setStyles } from './StyleHandler'; import { listenNonDelegatedEvent } from '../../event/EventBinding'; -import {isEventProp, isNativeElement} from '../validators/ValidateProps'; +import { isEventProp, isNativeElement } from '../validators/ValidateProps'; // 初始化DOM属性 export function setDomProps( @@ -31,14 +31,14 @@ export function updateDomProps( changeList: Array, isNativeTag: boolean, ): void { - for (let i = 0; i < changeList.length; i ++) { - const {propName, propVal} = changeList[i]; + for (let i = 0; i < changeList.length; i++) { + const { propName, propVal } = changeList[i]; updateOneProp(dom, propName, propVal, isNativeTag); } } -function updateOneProp(dom, propName, propVal, isNativeTag, isInit = false) { +function updateOneProp(dom, propName, propVal, isNativeTag, isInit?: boolean) { if (propName === 'style') { setStyles(dom, propVal); } else if (propName === 'dangerouslySetInnerHTML') { @@ -65,8 +65,8 @@ export function compareProps( newProps: Object, ): Array { let updatesForStyle = {}; - const toBeDeletedProps = []; - const toBeUpdatedProps = []; + const toBeDeletedProps: Array = []; + const toBeUpdatedProps: Array = []; const keysOfOldProps = Object.keys(oldProps); const keysOfNewProps = Object.keys(newProps); @@ -124,7 +124,7 @@ export function compareProps( const oldStyleProps = Object.keys(oldPropValue); for (let j = 0; j < oldStyleProps.length; j++) { const styleProp = oldStyleProps[j]; - if (!newPropValue || !newPropValue.hasOwnProperty(styleProp)) { + if (!newPropValue || !Object.prototype.hasOwnProperty.call(newPropValue, styleProp)) { updatesForStyle[styleProp] = ''; } } diff --git a/libs/horizon/src/dom/valueHandler/ValueChangeHandler.ts b/libs/horizon/src/dom/valueHandler/ValueChangeHandler.ts index b74aa6db..35d31e20 100644 --- a/libs/horizon/src/dom/valueHandler/ValueChangeHandler.ts +++ b/libs/horizon/src/dom/valueHandler/ValueChangeHandler.ts @@ -7,7 +7,7 @@ const HANDLER_KEY = '_valueChangeHandler'; // 判断是否是 check 类型 function isCheckType(dom: HTMLInputElement): boolean { - const {type, nodeName} = dom; + const { type, nodeName } = dom; if (nodeName && nodeName.toLowerCase() === 'input') { return type === 'checkbox' || type === 'radio'; } @@ -27,7 +27,7 @@ export function watchValueChange(dom) { // 获取 value 属性的描述信息,其 value 在其 constructor 的 原型上 const descriptor = Object.getOwnPropertyDescriptor(dom.constructor.prototype, keyForValue); - if (dom.hasOwnProperty(keyForValue)) { + if (Object.prototype.hasOwnProperty.call(dom, keyForValue)) { return; } @@ -37,7 +37,7 @@ export function watchValueChange(dom) { const setFunc = descriptor.set; Object.defineProperty(dom, keyForValue, { ...descriptor, - set: function(value) { + set: function (value) { currentVal = String(value); setFunc.apply(this, [value]); }, diff --git a/tsconfig.json b/tsconfig.json index 9190d6c3..f3af2c18 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -29,7 +29,8 @@ "types": [], // 赋值为空数组使@types/node不会起作用 "lib": ["dom", "esnext", "ES2015", "ES2016", "ES2017", "ES2018", "ES2019", "ES2020"], "baseUrl": ".", - "rootDir": "./libs" + "rootDir": "./libs", + "strictNullChecks": true }, "include": [ "./libs/**/src/**/*.ts",