From e54dde116a54fe6d800c3507af6e6304b9aeb6d3 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Tue, 28 Mar 2023 22:06:10 +0800 Subject: [PATCH 1/3] fix: copy-paste jsx-runtime types for global JSX namespace registration Otherwise TypeScript will raise TS2322 errors. I have no idea why and how does the fix work. But it does. Even importing the `ReservedProps` and `NativeElements` types from `jsx-runtime` instead of declaring them in the module would fail the tests. I have no idea why, either. The failing tests are at https://github.com/vuejs/ecosystem-ci/actions/runs/4538928668/jobs/7998297656#step:7:3 --- packages/vue/jsx.d.ts | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/packages/vue/jsx.d.ts b/packages/vue/jsx.d.ts index 4057d6afc9c..756654b70b4 100644 --- a/packages/vue/jsx.d.ts +++ b/packages/vue/jsx.d.ts @@ -1,15 +1,34 @@ // global JSX namespace registration -import { JSX as JSXInternal } from './jsx-runtime' +// somehow we have to copy=pase the jsx-runtime types here to make TypeScript happy +import { VNode, VNodeRef } from '@vue/runtime-dom' +import { IntrinsicElementAttributes } from './jsx-runtime/dom' + +export type ReservedProps = { + key?: string | number | symbol + ref?: VNodeRef + ref_for?: boolean + ref_key?: string +} + +export type NativeElements = { + [K in keyof IntrinsicElementAttributes]: IntrinsicElementAttributes[K] & + ReservedProps +} declare global { namespace JSX { - interface Element extends JSXInternal.Element {} - interface ElementClass extends JSXInternal.ElementClass {} - interface ElementAttributesProperty - extends JSXInternal.ElementAttributesProperty {} - interface IntrinsicElements extends JSXInternal.IntrinsicElements {} - interface IntrinsicAttributes extends JSXInternal.IntrinsicAttributes {} + export interface Element extends VNode {} + export interface ElementClass { + $props: {} + } + export interface ElementAttributesProperty { + $props: {} + } + export interface IntrinsicElements extends NativeElements { + // allow arbitrary elements + // @ts-ignore suppress ts:2374 = Duplicate string index signature. + [name: string]: any + } + export interface IntrinsicAttributes extends ReservedProps {} } } - -export {} From 5d36547a6430695da2d35cd153d7d06cdf5ec605 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Tue, 28 Mar 2023 23:30:58 +0800 Subject: [PATCH 2/3] fix: re-export all jsx dom types --- packages/vue/jsx.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/vue/jsx.d.ts b/packages/vue/jsx.d.ts index 756654b70b4..947a9904419 100644 --- a/packages/vue/jsx.d.ts +++ b/packages/vue/jsx.d.ts @@ -3,6 +3,8 @@ import { VNode, VNodeRef } from '@vue/runtime-dom' import { IntrinsicElementAttributes } from './jsx-runtime/dom' +export * from './jsx-runtime/dom' + export type ReservedProps = { key?: string | number | symbol ref?: VNodeRef From bd4580076ccda1ec4d3d0497d21d11191b8a6528 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Tue, 28 Mar 2023 23:40:42 +0800 Subject: [PATCH 3/3] fix: re-export in the `jsx-register` module --- packages/vue/types/jsx-register.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/vue/types/jsx-register.d.ts b/packages/vue/types/jsx-register.d.ts index a626f798c2a..af5d5f29023 100644 --- a/packages/vue/types/jsx-register.d.ts +++ b/packages/vue/types/jsx-register.d.ts @@ -2,3 +2,5 @@ // imports the global JSX namespace registration for compat. // TODO: remove in 3.4 import '../jsx' + +export * from '../jsx-runtime/dom'