diff --git a/.eslintrc.js b/.eslintrc.js index 1978360..8903758 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -32,6 +32,7 @@ module.exports = { "@typescript-eslint/no-unsafe-return": "off", "@typescript-eslint/no-non-null-assertion": "off", "@typescript-eslint/explicit-module-boundary-types": "off", + "@typescript-eslint/ban-types": "off", }, }, { diff --git a/src/h.ts b/src/h.ts index 3535168..7cfe7cb 100644 --- a/src/h.ts +++ b/src/h.ts @@ -2,7 +2,14 @@ import { vnode, VNode, VNodeData } from "./vnode"; import * as is from "./is"; export type VNodes = VNode[]; -export type VNodeChildElement = VNode | string | number | undefined | null; +export type VNodeChildElement = + | VNode + | string + | number + | String + | Number + | undefined + | null; export type ArrayOrElement = T | T[]; export type VNodeChildren = ArrayOrElement; diff --git a/test/unit/core.ts b/test/unit/core.ts index a201830..bb0625d 100644 --- a/test/unit/core.ts +++ b/test/unit/core.ts @@ -86,20 +86,16 @@ describe("snabbdom", function () { const vnode = h("a", {}, "I am a string"); assert.strictEqual(vnode.text, "I am a string"); }); - it("can create vnode with String obj content", function() { - var vnode = h("a", new String("b")); + it("can create vnode with String obj content", function () { + const vnode = h("a", new String("b")); assert.equal(vnode.text, "b"); }); - it("can create vnode with props and String obj content", function() { - var vnode = h("a", {}, new String("b")); + it("can create vnode with props and String obj content", function () { + const vnode = h("a", {}, new String("b")); assert.equal(vnode.text, "b"); }); - it("can create vnode with array String obj content", function() { - var vnode = h("a", ["b", new String("c")]); - assert.equal(vnode.text, "bc"); - }); - it("can create vnode with Number obj content", function() { - var vnode = h("a", new Number(1)); + it("can create vnode with Number obj content", function () { + const vnode = h("a", new Number(1)); assert.equal(vnode.text, "1"); }); it("can create vnode with null props", function () { @@ -206,8 +202,10 @@ describe("snabbdom", function () { } }); it("handles classes from both selector and property", function () { - elm = patch(vnode0, h("div", [h("i.has", { class: { classes: true } })])) - .elm; + elm = patch( + vnode0, + h("div", [h("i.has", { class: { classes: true } })]) + ).elm; assert(elm.firstChild.classList.contains("has"), "has `has` class"); assert( elm.firstChild.classList.contains("classes"), @@ -223,6 +221,10 @@ describe("snabbdom", function () { assert.strictEqual(elm.childNodes[0].tagName, "SPAN"); assert.strictEqual(elm.childNodes[1].textContent, "I am a string"); }); + it("can create vnode with array String obj content", function () { + elm = patch(vnode0, h("a", ["b", new String("c")])).elm; + assert.strictEqual(elm.innerHTML, "bc"); + }); it("can create elements with props", function () { elm = patch(vnode0, h("a", { props: { src: "http://localhost/" } })).elm; assert.strictEqual(elm.src, "http://localhost/"); @@ -809,9 +811,8 @@ describe("snabbdom", function () { }) ); const shufArr = shuffle(arr.slice(0)); - let elm: HTMLDivElement | HTMLSpanElement = document.createElement( - "div" - ); + let elm: HTMLDivElement | HTMLSpanElement = + document.createElement("div"); elm = patch(elm, vnode1).elm as HTMLSpanElement; for (i = 0; i < elms; ++i) { assert.strictEqual(elm.children[i].innerHTML, i.toString());