Add new definition: react-hyperscript (#20693)

* Add new package: react-hyperscript

* Type of function should be declared by function keyword...

* Add a workaround

tsc does not allow `export =`ing function because ES spec does not allow that.
But react-hyperscript does that.
So this workaround is required.
This commit is contained in:
Tomoki Ohno
2017-10-19 06:26:47 +09:00
committed by Andy
parent 0b214148d0
commit 288e9dd83f
4 changed files with 72 additions and 0 deletions

17
types/react-hyperscript/index.d.ts vendored Normal file
View File

@@ -0,0 +1,17 @@
// Type definitions for react-hyperscript 3.0
// Project: https://github.com/mlmorg/react-hyperscript
// Definitions by: tock203 <https://github.com/tock203>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
import { ComponentClass, StatelessComponent, ReactElement } from 'react';
declare namespace h {}
declare function h<P>(
componentOrTag: ComponentClass<P> | StatelessComponent<P> | string,
properties?: P,
children?: ReadonlyArray<ReactElement<any>> | string
): ReactElement<P>;
export = h;

View File

@@ -0,0 +1,31 @@
import * as React from 'react';
import * as h from 'react-hyperscript';
class SomeComponent extends React.Component {
render() {
return React.createElement('div');
}
}
const StatelessComponent = () => React.createElement('div');
class MainComponent extends React.Component {
render() {
return h('div.example', [
h('h1#heading', 'This is hyperscript'),
h('h2', 'creating React.js markup'),
h(SomeComponent, {foo: 'bar'}, [
h('li', [
h('a', {href: 'http://whatever.com'}, 'One list item')
]),
h('li', 'Another list item')
]),
h(StatelessComponent, {foo: 'bar'}, [
h('li', [
h('a', {href: 'http://whatever.com'}, 'One list item')
]),
h('li', 'Another list item')
])
]);
}
}

View File

@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"react-hyperscript-tests.ts"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }