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

Define component improvements #12612

Merged
merged 4 commits into from Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/core/util/next-tick.ts
Expand Up @@ -86,7 +86,8 @@ if (typeof Promise !== 'undefined' && isNative(Promise)) {
}

export function nextTick(): Promise<void>
export function nextTick(cb: (...args: any[]) => any, ctx?: object): void
export function nextTick<T>(this: T, cb: (this: T, ...args: any[]) => any): void
export function nextTick<T>(cb: (this: T, ...args: any[]) => any, ctx: T): void
/**
* @internal
*/
Expand Down
6 changes: 6 additions & 0 deletions types/common.d.ts
Expand Up @@ -13,3 +13,9 @@ type Equal<Left, Right> =
(<U>() => U extends Left ? 1 : 0) extends (<U>() => U extends Right ? 1 : 0) ? true : false;

export type HasDefined<T> = Equal<T, unknown> extends true ? false : true

// If the the type T accepts type "any", output type Y, otherwise output type N.
// https://stackoverflow.com/questions/49927523/disallow-call-with-any/49928360#49928360
export type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N

export type LooseRequired<T> = { [P in string & keyof T]: T[P] }
11 changes: 7 additions & 4 deletions types/index.d.ts
Expand Up @@ -30,7 +30,8 @@ export {
VNode,
VNodeComponentOptions,
VNodeData,
VNodeDirective
VNodeDirective,
ComponentCustomProps
} from './vnode'

export * from './v3-manual-apis'
Expand All @@ -47,13 +48,15 @@ export {
// v2 already has option with same name and it's for a single computed
ComputedOptions as ComponentComputedOptions,
MethodOptions as ComponentMethodOptions,
ComponentPropsOptions
ComponentPropsOptions,
ComponentCustomOptions
} from './v3-component-options'
export {
ComponentInstance,
ComponentPublicInstance,
ComponentRenderProxy
} from './v3-component-proxy'
CreateComponentPublicInstance,
ComponentCustomProperties
} from './v3-component-public-instance'
export {
// PropType,
// PropOptions,
Expand Down
12 changes: 10 additions & 2 deletions types/jsx.d.ts
Expand Up @@ -1313,7 +1313,12 @@ type NativeElements = {
>
}

import { VNode, VNodeData } from './vnode'
import {
VNode,
VNodeData,
ComponentCustomProps,
AllowedComponentProps
} from './vnode'

declare global {
namespace JSX {
Expand All @@ -1329,7 +1334,10 @@ declare global {
// @ts-ignore suppress ts:2374 = Duplicate string index signature.
[name: string]: any
}
interface IntrinsicAttributes extends ReservedProps {}
interface IntrinsicAttributes
extends ReservedProps,
AllowedComponentProps,
ComponentCustomProps {}
}
}

Expand Down
8 changes: 7 additions & 1 deletion types/options.d.ts
Expand Up @@ -2,6 +2,7 @@ import { Vue, CreateElement, CombinedVueInstance } from './vue'
import { VNode, VNodeData, VNodeDirective, NormalizedScopedSlot } from './vnode'
import { SetupContext } from './v3-setup-context'
import { DebuggerEvent } from './v3-generated'
import { DefineComponent } from './v3-define-component'

type Constructor = {
new (...args: any[]): any
Expand All @@ -19,6 +20,7 @@ export type Component<
| typeof Vue
| FunctionalComponentOptions<Props>
| ComponentOptions<never, Data, Methods, Computed, Props, SetupBindings>
| DefineComponent<any, any, any, any, any>

type EsModule<T> = T | { default: T }

Expand Down Expand Up @@ -174,7 +176,10 @@ export interface ComponentOptions<
el?: Element | string
template?: string
// hack is for functional component type inference, should not be used in user code
render?(createElement: CreateElement, hack: RenderContext<Props>): VNode
render?(
createElement: CreateElement,
hack: RenderContext<Props>
): VNode | null | void
renderError?(createElement: CreateElement, err: Error): VNode
staticRenderFns?: ((createElement: CreateElement) => VNode)[]

Expand All @@ -198,6 +203,7 @@ export interface ComponentOptions<
[key: string]:
| Component<any, any, any, any>
| AsyncComponent<any, any, any, any>
| DefineComponent<any, any, any, any, any, any, any, any, any, any>
}
transitions?: { [key: string]: object }
filters?: { [key: string]: Function }
Expand Down