mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
Add virtual-dom tests and fix syntax to appease DT's automated checkers
This commit is contained in:
parent
1e2a1e22e5
commit
df507c636c
33
virtual-dom/virtual-dom-tests.ts
Normal file
33
virtual-dom/virtual-dom-tests.ts
Normal file
@ -0,0 +1,33 @@
|
||||
/// <reference path="virtual-dom.d.ts" />
|
||||
import virtual_dom = require("virtual-dom");
|
||||
import VNode = virtual_dom.VNode;
|
||||
import h = virtual_dom.h;
|
||||
|
||||
function renderAny(object: any): VNode {
|
||||
if (object === undefined) {
|
||||
return h('i.undefined', 'undefined');
|
||||
}
|
||||
else if (object === null) {
|
||||
return h('b.null', 'null');
|
||||
}
|
||||
else if (Array.isArray(object)) {
|
||||
return h('span.array', ['[', object.map(renderAny), ']']);
|
||||
}
|
||||
else if (typeof object === 'object') {
|
||||
var object_children = Object.keys(object).map(key => {
|
||||
var child = object[key];
|
||||
return h('div', [
|
||||
h('span.key', [key, ':']),
|
||||
renderAny(child),
|
||||
]);
|
||||
});
|
||||
return h('div.object', object_children);
|
||||
}
|
||||
else if (typeof object === 'number') {
|
||||
return h('span.number', object.toString());
|
||||
}
|
||||
else if (typeof object === 'boolean') {
|
||||
return h('span.boolean', object.toString());
|
||||
}
|
||||
return h('span.string', object.toString());
|
||||
}
|
||||
26
virtual-dom/virtual-dom.d.ts
vendored
26
virtual-dom/virtual-dom.d.ts
vendored
@ -1,3 +1,8 @@
|
||||
// Type definitions for virtual-dom 2.0.1
|
||||
// Project: https://github.com/Matt-Esch/virtual-dom
|
||||
// Definitions by: Christopher Brown <https://github.com/chbrown>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
declare module VirtualDOM {
|
||||
interface VHook {
|
||||
hook(node: Element, propertyName: string): void;
|
||||
@ -39,7 +44,7 @@ declare module VirtualDOM {
|
||||
|
||||
interface VText {
|
||||
text: string;
|
||||
new (text: any);
|
||||
new(text: any): VText;
|
||||
version: string;
|
||||
type: string; // 'VirtualText'
|
||||
}
|
||||
@ -71,7 +76,7 @@ declare module VirtualDOM {
|
||||
// THUNK = 8
|
||||
// }
|
||||
interface VPatch {
|
||||
vNode: VNode,
|
||||
vNode: VNode;
|
||||
patch: any;
|
||||
new(type: number, vNode: VNode, patch: any): VPatch;
|
||||
version: string;
|
||||
@ -93,8 +98,8 @@ declare module VirtualDOM {
|
||||
create() calls either document.createElement() or document.createElementNS(),
|
||||
for which the common denominator is Element (not HTMLElement).
|
||||
*/
|
||||
function create(vnode: VText, opts?: {document?: Document, warn?: boolean}): Text;
|
||||
function create(vnode: VNode | Widget | Thunk, opts?: {document?: Document, warn?: boolean}): Element;
|
||||
function create(vnode: VText, opts?: {document?: Document; warn?: boolean}): Text;
|
||||
function create(vnode: VNode | Widget | Thunk, opts?: {document?: Document; warn?: boolean}): Element;
|
||||
function h(tagName: string, properties: createProperties, children: string | VChild[]): VNode;
|
||||
function h(tagName: string, children: string | VChild[]): VNode;
|
||||
function diff(left: VTree, right: VTree): VPatch[];
|
||||
@ -106,16 +111,21 @@ declare module VirtualDOM {
|
||||
}
|
||||
|
||||
declare module "virtual-dom/h" {
|
||||
export = VirtualDOM.h;
|
||||
// export = VirtualDOM.h; works just fine, but the DT checker doesn't like it
|
||||
import h = VirtualDOM.h;
|
||||
export = h;
|
||||
}
|
||||
declare module "virtual-dom/create-element" {
|
||||
export = VirtualDOM.create;
|
||||
import create = VirtualDOM.create;
|
||||
export = create;
|
||||
}
|
||||
declare module "virtual-dom/diff" {
|
||||
export = VirtualDOM.diff;
|
||||
import diff = VirtualDOM.diff;
|
||||
export = diff;
|
||||
}
|
||||
declare module "virtual-dom/patch" {
|
||||
export = VirtualDOM.patch;
|
||||
import patch = VirtualDOM.patch;
|
||||
export = patch;
|
||||
}
|
||||
declare module "virtual-dom" {
|
||||
export = VirtualDOM;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user