Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(jsx-types): namespace JSX types #7083

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"test": "run-s \"test-unit {@}\" \"test-e2e {@}\"",
"test-unit": "jest --filter ./scripts/filter-unit.js",
"test-e2e": "node scripts/build.js vue -f global -d && jest --filter ./scripts/filter-e2e.js --runInBand",
"test-dts": "node scripts/build.js shared reactivity runtime-core runtime-dom -dt -f esm-bundler && npm run test-dts-only",
"test-dts": "node scripts/build.js shared reactivity runtime-core jsx runtime-dom -dt -f esm-bundler && npm run test-dts-only",
"test-dts-only": "tsc -p ./test-dts/tsconfig.json && tsc -p ./test-dts/tsconfig.build.json",
"test-coverage": "node scripts/build.js vue -f global -d && jest --runInBand --coverage --bail",
"release": "node scripts/release.js",
Expand Down
7 changes: 7 additions & 0 deletions packages/jsx/api-extractor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../../api-extractor.json",
"mainEntryPointFilePath": "./dist/packages/<unscopedPackageName>/src/index.d.ts",
"dtsRollup": {
"publicTrimmedFilePath": "./dist/<unscopedPackageName>.d.ts"
}
}
35 changes: 35 additions & 0 deletions packages/jsx/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "@vue/jsx",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope it's okay to use @vue/jsx as package name.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's more like @vue/tsx though 😂
Unless we are planning to add more functionalities to this package later.

"version": "3.2.44",
"description": "@vue/jsx",
"main": "dist/jsx.cjs.js",
"types": "dist/jsx.d.ts",
"files": [
"register.d.ts",
"dist"
],
"buildOptions": {
"formats": [
"cjs"
]
},
"sideEffects": false,
"repository": {
"type": "git",
"url": "git+https://github.com/vuejs/core.git",
"directory": "packages/jsx"
},
"keywords": [
"vue"
],
"author": "Rahul Kadyan",
"license": "MIT",
"bugs": {
"url": "https://github.com/vuejs/core/issues"
},
"homepage": "https://github.com/vuejs/core/tree/main/packages/jsx#readme",
"dependencies": {
"csstype": "^3.1.1",
"@vue/runtime-core": "3.2.44"
}
}
15 changes: 15 additions & 0 deletions packages/jsx/register.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { h } from './dist/jsx'

declare global {
namespace JSX {
interface Element extends h.JSX.Element {}
interface ElementClass extends h.JSX.ElementClass {}
interface ElementAttributesProperty
extends h.JSX.ElementAttributesProperty {}
interface IntrinsicElements extends h.JSX.IntrinsicElements {}
interface IntrinsicAttributes extends h.JSX.IntrinsicAttributes {}
interface ElementChildrenAttribute extends h.JSX.ElementChildrenAttribute {}
}
}

export {}
18 changes: 18 additions & 0 deletions packages/jsx/src/css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as CSS from 'csstype'

export interface CSSProperties
extends CSS.Properties<string | number>,
CSS.PropertiesHyphen<string | number> {
/**
* The index signature was removed to enable closed typing for style
* using CSSType. You're able to use type assertion or module augmentation
* to add properties or an index signature of your own.
*
* For examples and more information, visit:
* https://github.com/frenic/csstype#what-should-i-do-when-i-get-type-errors
*/
[v: `--${string}`]: string | number | undefined
}

// Vue's style normalization supports nested arrays
export type StyleValue = string | CSSProperties | Array<StyleValue>
39 changes: 39 additions & 0 deletions packages/jsx/src/h.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { type VNode, h as _h } from '@vue/runtime-core'
import { type HTMLElementAttributesMap } from './html'
import { type SVGElementAttributesMap } from './svg'
import { type ReservedProps } from './vue'

type ElementAttrs<T> = T & ReservedProps
type NativeElements = {
[K in keyof HTMLElementAttributesMap]: ElementAttrs<
HTMLElementAttributesMap[K]
>
} & {
[K in keyof SVGElementAttributesMap]: ElementAttrs<SVGElementAttributesMap[K]>
}

/**
* This is only for type support.
* @public
*/
export const h = _h
export namespace h {
export namespace JSX {
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 interface ElementChildrenAttribute {
$slots: {}
Copy link
Member Author

@znck znck Nov 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this count as breaking change?

ElementChildrenAttribute sets the name of children within props. https://www.typescriptlang.org/docs/handbook/jsx.html#children-type-checking

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vuetify uses $children. Volar uses $slots but it isn't inside $props so doesn't count.

}
}
}
Loading