diff --git a/.eslintrc.js b/.eslintrc.js index ab441a7..d4b958f 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -2,7 +2,6 @@ module.exports = { extends: 'standard-with-typescript', parserOptions: { project: [ './tsconfig.json', ] }, rules: { - '@typescript-eslint/array-type': 'off', '@typescript-eslint/brace-style': 'off', '@typescript-eslint/consistent-type-assertions': 'off', '@typescript-eslint/consistent-type-definitions': 'off', diff --git a/src/h.ts b/src/h.ts index 9b9886c..ed4593e 100644 --- a/src/h.ts +++ b/src/h.ts @@ -1,5 +1,5 @@ import {vnode, VNode, VNodeData} from './vnode'; -export type VNodes = Array; +export type VNodes = VNode[]; export type VNodeChildElement = VNode | string | number | undefined | null; export type ArrayOrElement = T | T[]; export type VNodeChildren = ArrayOrElement diff --git a/src/modules/style.ts b/src/modules/style.ts index 9514913..33dc57f 100755 --- a/src/modules/style.ts +++ b/src/modules/style.ts @@ -73,7 +73,7 @@ function applyRemoveStyle(vnode: VNode, rm: () => void): void { reflowForced = true; } var name: string, elm = vnode.elm, i = 0, compStyle: CSSStyleDeclaration, - style = s.remove, amount = 0, applied: Array = []; + style = s.remove, amount = 0, applied: string[] = []; for (name in style) { applied.push(name); (elm as any).style[name] = style[name]; diff --git a/src/snabbdom.ts b/src/snabbdom.ts index a6f976b..a61be9f 100644 --- a/src/snabbdom.ts +++ b/src/snabbdom.ts @@ -8,7 +8,7 @@ import htmlDomApi, {DOMAPI} from './htmldomapi'; function isUndef(s: any): boolean { return s === undefined; } function isDef(s: any): boolean { return s !== undefined; } -type VNodeQueue = Array; +type VNodeQueue = VNode[]; const emptyNode = vnode('', {}, [], undefined, undefined); @@ -23,12 +23,12 @@ function isVnode(vnode: any): vnode is VNode { type KeyToIndexMap = {[key: string]: number}; type ArraysOf = { - [K in keyof T]: (T[K])[]; + [K in keyof T]: Array; } type ModuleHooks = ArraysOf; -function createKeyToOldIdx(children: Array, beginIdx: number, endIdx: number): KeyToIndexMap { +function createKeyToOldIdx(children: VNode[], beginIdx: number, endIdx: number): KeyToIndexMap { let i: number, map: KeyToIndexMap = {}, key: Key | undefined, ch; for (i = beginIdx; i <= endIdx; ++i) { ch = children[i]; @@ -40,7 +40,7 @@ function createKeyToOldIdx(children: Array, beginIdx: number, endIdx: num return map; } -const hooks: (keyof Module)[] = ['create', 'update', 'remove', 'destroy', 'pre', 'post']; +const hooks: Array = ['create', 'update', 'remove', 'destroy', 'pre', 'post']; export {h} from './h'; export {thunk} from './thunk'; @@ -55,7 +55,7 @@ export function init(modules: Array>, domApi?: DOMAPI) { for (j = 0; j < modules.length; ++j) { const hook = modules[j][hooks[i]]; if (hook !== undefined) { - (cbs[hooks[i]] as Array).push(hook); + (cbs[hooks[i]] as any[]).push(hook); } } } @@ -126,7 +126,7 @@ export function init(modules: Array>, domApi?: DOMAPI) { function addVnodes( parentElm: Node, before: Node | null, - vnodes: Array, + vnodes: VNode[], startIdx: number, endIdx: number, insertedVnodeQueue: VNodeQueue @@ -156,7 +156,7 @@ export function init(modules: Array>, domApi?: DOMAPI) { } function removeVnodes(parentElm: Node, - vnodes: Array, + vnodes: VNode[], startIdx: number, endIdx: number): void { for (; startIdx <= endIdx; ++startIdx) { @@ -180,8 +180,8 @@ export function init(modules: Array>, domApi?: DOMAPI) { } function updateChildren(parentElm: Node, - oldCh: Array, - newCh: Array, + oldCh: VNode[], + newCh: VNode[], insertedVnodeQueue: VNodeQueue) { let oldStartIdx = 0, newStartIdx = 0; let oldEndIdx = oldCh.length - 1; @@ -269,18 +269,18 @@ export function init(modules: Array>, domApi?: DOMAPI) { } if (isUndef(vnode.text)) { if (isDef(oldCh) && isDef(ch)) { - if (oldCh !== ch) updateChildren(elm, oldCh as Array, ch as Array, insertedVnodeQueue); + if (oldCh !== ch) updateChildren(elm, oldCh as VNode[], ch as VNode[], insertedVnodeQueue); } else if (isDef(ch)) { if (isDef(oldVnode.text)) api.setTextContent(elm, ''); - addVnodes(elm, null, ch as Array, 0, (ch as Array).length - 1, insertedVnodeQueue); + addVnodes(elm, null, ch as VNode[], 0, (ch as VNode[]).length - 1, insertedVnodeQueue); } else if (isDef(oldCh)) { - removeVnodes(elm, oldCh as Array, 0, (oldCh as Array).length - 1); + removeVnodes(elm, oldCh as VNode[], 0, (oldCh as VNode[]).length - 1); } else if (isDef(oldVnode.text)) { api.setTextContent(elm, ''); } } else if (oldVnode.text !== vnode.text) { if (isDef(oldCh)) { - removeVnodes(elm, oldCh as Array, 0, (oldCh as Array).length - 1); + removeVnodes(elm, oldCh as VNode[], 0, (oldCh as VNode[]).length - 1); } api.setTextContent(elm, vnode.text as string); } diff --git a/src/thunk.ts b/src/thunk.ts index 3ff05a7..1646fda 100644 --- a/src/thunk.ts +++ b/src/thunk.ts @@ -3,7 +3,7 @@ import {h} from './h'; export interface ThunkData extends VNodeData { fn: () => VNode; - args: Array; + args: any[]; } export interface Thunk extends VNode { @@ -11,8 +11,8 @@ export interface Thunk extends VNode { } export interface ThunkFn { - (sel: string, fn: Function, args: Array): Thunk; - (sel: string, key: any, fn: Function, args: Array): Thunk; + (sel: string, fn: Function, args: any[]): Thunk; + (sel: string, key: any, fn: Function, args: any[]): Thunk; } function copyToThunk(vnode: VNode, thunk: VNode): void { diff --git a/src/tovnode.ts b/src/tovnode.ts index 98e0564..67fef5d 100644 --- a/src/tovnode.ts +++ b/src/tovnode.ts @@ -10,7 +10,7 @@ export function toVNode(node: Node, domApi?: DOMAPI): VNode { const c = cn ? '.' + cn.split(' ').join('.') : ''; const sel = api.tagName(node).toLowerCase() + id + c; const attrs: any = {}; - const children: Array = []; + const children: VNode[] = []; let name: string; let i: number, n: number; const elmAttrs = node.attributes; diff --git a/src/vnode.ts b/src/vnode.ts index 37512d9..1ebe7e7 100644 --- a/src/vnode.ts +++ b/src/vnode.ts @@ -32,7 +32,7 @@ export interface VNodeData { key?: Key; ns?: string; // for SVGs fn?: () => VNode; // for thunks - args?: Array; // for thunks + args?: any[]; // for thunks [key: string]: any; // for any other 3rd party module }