Skip to content

types(slots): Add typed slots #2693

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

Closed
wants to merge 12 commits into from
Prev Previous commit
Next Next commit
chore: Merge branch 'master-upstream' into feat/typed_slots
# Conflicts:
#	packages/runtime-core/src/componentOptions.ts
  • Loading branch information
pikax committed Aug 20, 2021
commit 5300104c288c21113b14772fde7990503ae69114
4 changes: 1 addition & 3 deletions packages/compiler-core/__tests__/transforms/vSlot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -780,9 +780,7 @@ describe('compiler: transform component slots', () => {
})

test('<slot w/ nested component>', () => {
const { slots } = parseWithSlots(
`<Comp><Comp><slot/></Comp></Comp>`
)
const { slots } = parseWithSlots(`<Comp><Comp><slot/></Comp></Comp>`)
expect(slots).toMatchObject(toMatch)
})
})
Expand Down
3 changes: 2 additions & 1 deletion packages/compiler-sfc/src/cssVars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { PluginCreator } from 'postcss'
import hash from 'hash-sum'

export const CSS_VARS_HELPER = `useCssVars`
export const cssVarRE = /\bv-bind\(\s*(?:'([^']+)'|"([^"]+)"|([^'"][^)]*))\s*\)/g
export const cssVarRE =
/\bv-bind\(\s*(?:'([^']+)'|"([^"]+)"|([^'"][^)]*))\s*\)/g

export function genCssVarsFromList(
vars: string[],
Expand Down
4 changes: 3 additions & 1 deletion packages/runtime-core/src/compat/componentFunctional.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ const normalizedFunctionalComponentMap = new Map<
FunctionalComponent
>()

export const legacySlotProxyHandlers: ProxyHandler<InternalSlots> = {
export const legacySlotProxyHandlers: ProxyHandler<
InternalSlots<Record<string, null>>
> = {
get(target, key: string) {
const slot = target[key]
return slot && slot()
Expand Down
32 changes: 24 additions & 8 deletions packages/runtime-core/src/componentOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,15 @@ import {
import { warn } from './warning'
import { VNodeChild } from './vnode'
import { callWithAsyncErrorHandling } from './errorHandling'
import { UnionToIntersection } from './helpers/typeUtils'
import { LooseRequired, UnionToIntersection } from './helpers/typeUtils'
import { deepMergeData } from './compat/data'
import { DeprecationTypes } from './compat/compatConfig'
import {
CompatConfig,
isCompatEnabled,
softAssertCompatEnabled
} from './compat/compatConfig'
import { OptionMergeFunction } from './apiCreateApp'
import { Slots } from './componentSlots'

/**
Expand Down Expand Up @@ -115,9 +123,13 @@ export interface ComponentOptionsBase<
ComponentCustomOptions {
setup?: (
this: void,
props: Props &
UnionToIntersection<ExtractOptionProp<Mixin>> &
UnionToIntersection<ExtractOptionProp<Extends>>,
props: Readonly<
LooseRequired<
Props &
UnionToIntersection<ExtractOptionProp<Mixin>> &
UnionToIntersection<ExtractOptionProp<Extends>>
>
>,
ctx: SetupContext<E, Slots<S>>
) => Promise<RawBindings> | RawBindings | RenderFunction | void
name?: string
Expand All @@ -136,6 +148,9 @@ export interface ComponentOptionsBase<
expose?: string[]
serverPrefetch?(): Promise<any>

// Runtime compiler only -----------------------------------------------------
compilerOptions?: RuntimeCompilerOptions

slots?: S & ThisType<void>

// Internal ------------------------------------------------------------------
Expand Down Expand Up @@ -211,7 +226,8 @@ export type ComponentOptionsWithoutProps<
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
E extends EmitsOptions = EmitsOptions,
EE extends string = string,
S = any
S = any,
PE = Props & EmitsToProps<E>
> = ComponentOptionsBase<
PE,
RawBindings,
Expand All @@ -228,7 +244,7 @@ export type ComponentOptionsWithoutProps<
props?: undefined
} & ThisType<
CreateComponentPublicInstance<
{},
PE,
RawBindings,
D,
C,
Expand All @@ -251,7 +267,7 @@ export type ComponentOptionsWithArrayProps<
E extends EmitsOptions = EmitsOptions,
EE extends string = string,
S = any,
Props = Readonly<{ [key in PropNames]?: any }>
Props = Readonly<{ [key in PropNames]?: any }> & EmitsToProps<E>
> = ComponentOptionsBase<
Props,
RawBindings,
Expand Down Expand Up @@ -291,7 +307,7 @@ export type ComponentOptionsWithObjectProps<
E extends EmitsOptions = EmitsOptions,
EE extends string = string,
S = any,
Props = Readonly<ExtractPropTypes<PropsOptions>>,
Props = Readonly<ExtractPropTypes<PropsOptions>> & EmitsToProps<E>,
Defaults = ExtractDefaultPropTypes<PropsOptions>
> = ComponentOptionsBase<
Props,
Expand Down
4 changes: 2 additions & 2 deletions packages/runtime-core/src/componentSlots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export type Slots<T = any> = RenderSlot &
(unknown extends T
? Readonly<Partial<Record<string, Slot>>>
: T extends Array<infer V>
? Readonly<SlotArray<V>>
: Readonly<SlotsObject<T>>)
? Readonly<SlotArray<V>>
: Readonly<SlotsObject<T>>)

export type RenderSlot = {
// manual render fn hint to skip forced children updates
Expand Down
5 changes: 1 addition & 4 deletions packages/runtime-core/src/scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,7 @@ function queueCb(
if (!isArray(cb)) {
if (
!activeQueue ||
!activeQueue.includes(
cb,
cb.allowRecurse ? index + 1 : index
)
!activeQueue.includes(cb, cb.allowRecurse ? index + 1 : index)
) {
pendingQueue.push(cb)
}
Expand Down
6 changes: 3 additions & 3 deletions test-dts/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export function expectType<T>(value: T): void
export function expectError<T>(value: T): void
export function expectAssignable<T, T2 extends T = T>(value: T2): void

export type IsUnion<T, U extends T = T> = (T extends any
? (U extends T ? false : true)
: never) extends false
export type IsUnion<T, U extends T = T> = (
T extends any ? (U extends T ? false : true) : never
) extends false
? false
: true
You are viewing a condensed version of this merge commit. You can view the full changes here.