@@ -272,20 +272,18 @@ extendAsHTMLElement(
272
272
273
273
You don't necessarily need to you `DeclareComponent`, but you can.
274
274
275
- > Is necessary to use `new<...>{ $props : { ... } } ` for Generic components.
275
+ > Is necessary to use `new<...>{ $props : { ... } } ` for Generic components, using type helpers with Generic params might break generic types .
276
276
277
277
```ts
278
278
type ErrorLevel = 'debug' | 'warning' | 'error'
279
279
280
280
declare function ErrorComponent<T >(options: T): T &
281
- DeclareComponent<{
282
281
new <T extends ErrorLevel = ' debug' >(): {
283
282
$props : { type: T } & {
284
283
[K in ` on${Capitalize < T > } ` ]: (msg : string ) => void
285
284
}
286
285
$slots : SlotsType < Record < T , (msg : string ) => any []>>
287
286
}
288
- }>
289
287
290
288
const Comp = ErrorComponent(
291
289
defineComponent({
@@ -415,3 +413,70 @@ Returns the component bindings from `data` and `setup`.
415
413
```ts
416
414
417
415
```
416
+
417
+ ## DefineComponentOptions & DefineComponentFromOptions { #definecomponentoptions }
418
+
419
+ Allows to get vue component options and generate `DefineComponent` type.
420
+
421
+ :::warning
422
+ The generic order is not prone to change, but it might, `Options` should be the last generic used, new generics will be added before `Options`.
423
+ :::
424
+
425
+ :::info
426
+ Note that you if you need to handle generics, it should be it's own overload, since
427
+ any change to the Generic definition might break the Generic type.
428
+ :::
429
+
430
+ ```ts
431
+ declare function defineComponentWithDefaults<
432
+ Props = never,
433
+ RawBindings = { } ,
434
+ D = { } ,
435
+ C extends ComputedOptions = { } ,
436
+ M extends MethodOptions = { } ,
437
+ Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
438
+ Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
439
+ E extends EmitsOptions = { } ,
440
+ EE extends string = string,
441
+ I extends ComponentInjectOptions = { } ,
442
+ II extends string = string,
443
+ S extends SlotsType = { } ,
444
+ Options extends { } = { }
445
+ >(
446
+ options: DefineComponentOptions<
447
+ Props,
448
+ RawBindings,
449
+ D,
450
+ C,
451
+ M,
452
+ Mixin,
453
+ Extends,
454
+ E,
455
+ EE,
456
+ I,
457
+ II,
458
+ S,
459
+ Options
460
+ >,
461
+ defaults: Partial<
462
+ [Props] extends [string]
463
+ ? { [K in Props ]?: any }
464
+ : ExtractPropTypes<Props >
465
+ >
466
+ ): DefineComponentFromOptions<
467
+ undefined extends Props ? { } : Props,
468
+ RawBindings,
469
+ D,
470
+ C,
471
+ M,
472
+ Mixin,
473
+ Extends,
474
+ E,
475
+ EE,
476
+ I,
477
+ II,
478
+ S,
479
+ Options
480
+ >
481
+ ```
482
+
0 commit comments