TS2605:JSX元素类型'VNode <attributes> | View <state,actions =“”>'不是JSX元素的构造函数

时间:2018-12-25 01:48:50

标签: typescript hyperapp

hyperapp.d.ts文件

export interface VNode<Attributes = {}> {
  nodeName: string
  attributes?: Attributes
  children: Array<VNode | string>
  key: string
}


export interface Component<Attributes = {}, State = {}, Actions = {}> {
  (attributes: Attributes, children: Array<VNode | string>):
    | VNode<Attributes>
    | View<State, Actions>
}

declare global {
  namespace JSX {
    interface Element extends VNode<any> {}
    interface IntrinsicElements {
      [elemName: string]: any
    }
  }
}

我的代码

export const Up: Component<Attributes, State, Actions> = ({ by }) => (_, actions) => (
  <button onclick={() => actions.up(by)}>+ {by}</button>
)

export const Down: Component<Attributes, State, Actions> = ({ by }) => (_, actions) => (
  <button onclick={() => actions.down(by)}>- {by}</button>
)

export const Double: Component<{}, State, Actions> = () => (state, actions) => (
  <button onclick={() => actions.up(state.count)}>+ {state.count}</button>
)

export const view: View<State, Actions> = state => (
  <div>
    <h1>{state.count}</h1>
    <Up by={2} />
    <Down by={1} />
    <Double />
  </div>
)

错误消息

* TS2605:JSX元素类型'VNode | “视图”不是JSX元素的构造函数。   不能将“视图”类型分配给“元素”类型。

TS2605:JSX元素类型“视图| VNode <{}>'不是JSX元素的构造函数。   无法将“视图”类型分配给“元素”类型。*

0 个答案:

没有答案