Skip to content

Commit 439d5b1

Browse files
committed
chore: add comments
1 parent 694ac09 commit 439d5b1

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

packages/runtime-core/src/apiDefineComponent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
SetupContext,
1717
AllowedComponentProps,
1818
ComponentCustomProps,
19-
HasDefineAttrs
19+
noAttrsDefine
2020
} from './component'
2121
import {
2222
ExtractPropTypes,
@@ -109,7 +109,7 @@ export function defineComponent<
109109
EE extends string = string,
110110
S extends SlotsType = {},
111111
Attrs extends AttrsType = Record<string, unknown>,
112-
PropsAttrs = HasDefineAttrs<Attrs> extends true
112+
PropsAttrs = noAttrsDefine<Attrs> extends true
113113
? {}
114114
: UnwrapAttrsType<NonNullable<Attrs>>
115115
>(

packages/runtime-core/src/component.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ import { SchedulerJob } from './scheduler'
8484
import { LifecycleHooks } from './enums'
8585

8686
export type Data = Record<string, unknown>
87-
export type HasDefineAttrs<T> = Equal<keyof T, string>
87+
// Whether the attrs option is not defined
88+
export type noAttrsDefine<T> = Equal<keyof T, string>
8889
/**
8990
* For extending allowed non-declared props on components in TSX
9091
*/
@@ -191,7 +192,7 @@ export type SetupContext<
191192
Attrs extends AttrsType = Record<string, unknown>
192193
> = E extends any
193194
? {
194-
attrs: HasDefineAttrs<Attrs> extends true
195+
attrs: noAttrsDefine<Attrs> extends true
195196
? Data
196197
: UnwrapAttrsType<NonNullable<Attrs>>
197198
slots: UnwrapSlotsType<S>

packages/runtime-core/src/componentPublicInstance.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {
22
AllowedComponentProps,
33
ComponentInternalInstance,
44
Data,
5-
HasDefineAttrs,
5+
noAttrsDefine,
66
getExposeProxy,
77
isStatefulComponent
88
} from './component'
@@ -210,19 +210,20 @@ export type ComponentPublicInstance<
210210
Options = ComponentOptionsBase<any, any, any, any, any, any, any, any, any>,
211211
I extends ComponentInjectOptions = {},
212212
S extends SlotsType = {},
213-
Attrs extends AttrsType = Record<string, unknown>,
214-
PropsAttrs = HasDefineAttrs<Attrs> extends true
215-
? {}
216-
: Omit<UnwrapAttrsType<Attrs>, keyof (P & PublicProps)>
213+
Attrs extends AttrsType = Record<string, unknown>, // Attrs type extracted from attrs option
214+
// AttrsProps type used for JSX validation of attrs
215+
AttrsProps = noAttrsDefine<Attrs> extends true // if attrs is not defined
216+
? {} // no JSX validation of attrs
217+
: Omit<UnwrapAttrsType<Attrs>, keyof (P & PublicProps)> // exclude props from attrs, for JSX validation
217218
> = {
218219
$: ComponentInternalInstance
219220
$data: D
220221
$props: Prettify<
221222
MakeDefaultsOptional extends true
222-
? Partial<Defaults> & Omit<P & PublicProps, keyof Defaults> & PropsAttrs
223-
: P & PublicProps & PropsAttrs
223+
? Partial<Defaults> & Omit<P & PublicProps, keyof Defaults> & AttrsProps
224+
: P & PublicProps & AttrsProps
224225
>
225-
$attrs: HasDefineAttrs<Attrs> extends true
226+
$attrs: noAttrsDefine<Attrs> extends true
226227
? Data
227228
: Omit<UnwrapAttrsType<Attrs>, keyof (P & PublicProps)> &
228229
AllowedComponentProps

packages/shared/src/typeUtils.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ export type Awaited<T> = T extends null | undefined
2424

2525
// Conditional returns can enforce identical types.
2626
// See here: https://github.com/Microsoft/TypeScript/issues/27024#issuecomment-421529650
27-
// prettier-ignore
28-
export type Equal<Left, Right> =
29-
(<U>() => U extends Left ? 1 : 0) extends (<U>() => U extends Right ? 1 : 0) ? true : false;
27+
export type Equal<Left, Right> = (<U>() => U extends Left ? 1 : 0) extends <
28+
U
29+
>() => U extends Right ? 1 : 0
30+
? true
31+
: false

0 commit comments

Comments
 (0)