Vue-next: Add types for vue h

Created on 13 Jun 2020  路  6Comments  路  Source: vuejs/vue-next

Add these codes in vue-next/packages/runtime-dom/types/jsx.d.ts

import {
  VNode,
  VNodeArrayChildren,
  VNodeProps,
  ComponentInternalInstance,
} from '@vue/runtime-core';

declare module 'vue' {
  // copy from @vue/runtime-core
  type RawChildren =
    | string
    | number
    | boolean
    | VNode
    | VNodeArrayChildren
    | (() => any);
  // copy from @vue/runtime-core
  type RawProps = VNodeProps & {
    __v_isVNode?: never;
    [Symbol.iterator]?: never;
  };
  // copy from @vue/runtime-core
  type RawSlots = {
    [name: string]: unknown;
    $stable?: boolean;
    _ctx?: ComponentInternalInstance | null;
    _?: 1;
  }; 

  export function h<K extends StringKeyOf<IntrinsicElementAttributes>>(
    type: K ,
    props?: RawProps & ElementAttrs< 
    IntrinsicElementAttributes[K]
  > | null,
    children?: RawChildren | RawSlots
  ): VNode;
}

These codes will help us to do type checking with @vuedx/typecheck


Another Question: What help does @vuedx need? It seems that its development has stoped for several weeks.

Most helpful comment

this issue is still actionable.

See example:

import { h } from 'vue'
// @ts-expect-error Parameter 'event' implicitly has an 'any' type.ts(7006)
export default h('button',{ onClick: event => { console.log(event) } })

All 6 comments

@xiaoxiangmoe is this still relevant? There have been significant changes been done to jsx.d.ts, so can you please respond wether this issue is still actionable or can be closed?

Thanks!

this issue is still actionable.

See example:

import { h } from 'vue'
// @ts-expect-error Parameter 'event' implicitly has an 'any' type.ts(7006)
export default h('button',{ onClick: event => { console.log(event) } })

Thanks

Now, I'm not using h in TS plugin but I'll confirm if this affects JSX or not.

@znck Could you sharing us the reason why not using h in TS plugin. Thank you.

Template is converted to TSX so h is not required for type checking.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

NMFES picture NMFES  路  3Comments

skirtles-code picture skirtles-code  路  3Comments

HakamFostok picture HakamFostok  路  3Comments

adamberecz picture adamberecz  路  3Comments

crutchcorn picture crutchcorn  路  3Comments