1

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 | View' 不是 JSX 元素的构造函数。类型“视图”不可分配给类型“元素”。

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

4

0 回答 0