@@ -365,15 +365,27 @@ Converts an Record<string, any> into a props definition like object.
365
365
Useful for extending component props.
366
366
367
367
```ts
368
-
368
+ const props: ObjectToComponentProps<{ foo : ' bar' | ' baz' , baz ?: number } >
369
+ // props is:
370
+ {
371
+ foo : {
372
+ type: Prop < ' bar' | ' baz' > ,
373
+ required: true
374
+ },
375
+ baz : {
376
+ type: Prop < number > ,
377
+ required: false
378
+ }
379
+ }
369
380
```
370
381
371
382
## ComponentEmitsAsProps\<T > { #componentemitsasprops }
372
383
373
- Converts `Emit` declaration into `props` declaration.
384
+ Converts `Emit` declaration into `props` declaration, returned object will be optional .
374
385
375
386
```ts
376
-
387
+ declare const emit: ComponentEmitsAsProps<{ emits : { foo : () => true } } >
388
+ emit.onFoo?.() // ok
377
389
```
378
390
379
391
## ComponentProps\<T > { #componentprops }
@@ -395,23 +407,53 @@ props.foo // string | undefined
395
407
Returns runtime slots for a component.
396
408
397
409
```ts
410
+ const Comp = defineComponent({
411
+ slots : {} as SlotsType <{
412
+ default: (arg : { msg: string }) => any
413
+ }>
414
+ } )
398
415
416
+ const slots = { } as ComponentSlots<typeof Comp >
417
+ slots.default // { arg : { msg: string } } => any
399
418
```
400
419
401
420
## ComponentEmit\<T > { #componentemit }
402
421
403
422
Returns the `emit` function from options.
404
423
405
424
```ts
425
+ const CompSlotsTyped = defineComponent({
426
+ emits : {
427
+ foo : (arg : string ) => true
428
+ }
429
+ } )
406
430
431
+ const emit = { } as ComponentEmit<typeof CompSlotsTyped >
432
+ emit // (event: 'foo', arg: string) => void
407
433
```
408
434
409
435
## ComponentData\<T > { #componentdata }
410
436
411
437
Returns the component bindings from `data` and `setup`.
412
438
413
439
```ts
440
+ const Comp = defineComponent({
441
+ data () {
442
+ return {
443
+ foo : ' string'
444
+ }
445
+ },
446
+
447
+ setup (props , ctx ) {
448
+ return {
449
+ bar : 42
450
+ }
451
+ }
452
+ } )
414
453
454
+ const data = { } as ComponentData<typeof Comp >
455
+ data.foo // string
456
+ data.bar // number
415
457
```
416
458
417
459
## DefineComponentOptions & DefineComponentFromOptions { #definecomponentoptions }
@@ -479,4 +521,3 @@ declare function defineComponentWithDefaults<
479
521
Options
480
522
>
481
523
```
482
-
0 commit comments