quasar

Форк
0
/
ts-helpers.d.ts 
65 строк · 3.0 Кб
1
import {
2
  ComponentOptions,
3
  ComponentPublicInstance,
4
  ComputedOptions,
5
  MethodOptions,
6
  VNodeProps,
7
  AllowedComponentProps,
8
  ComponentCustomProps,
9
} from "vue";
10

11
export type StringDictionary<T extends string> = Required<{
12
  [index in T]: string;
13
}>;
14

15
// Needed to prevent TS to collapse `'value1' | 'value2' | string` to `string`, which breaks first parameter autocomplete
16
// See: https://github.com/microsoft/TypeScript/issues/29729#issuecomment-832522611
17
export type LiteralUnion<T extends U, U = string> =
18
  | T
19
  | (U & Record<never, never>);
20

21
// See: https://stackoverflow.com/a/49936686/7931540
22
export type DeepPartial<T> = {
23
  [P in keyof T]?: T[P] extends Array<infer U>
24
    ? Array<DeepPartial<U>>
25
    : T[P] extends ReadonlyArray<infer U>
26
      ? ReadonlyArray<DeepPartial<U>>
27
      : DeepPartial<T[P]>;
28
};
29

30
// Create a fake constructor signature for a Vue component, needed to correctly extract/infer Component type in many situation,
31
// especially into VTU to automatically infer Quasar components type when using `findComponent`
32
// This type is compatible with the Vue private `ComponentPublicInstanceConstructor` type
33
// https://github.com/vuejs/vue-next/blob/011dee8644bb52f5bdc6365c6e8404936d57e2cd/packages/runtime-core/src/componentPublicInstance.ts#L111
34
export type ComponentConstructor<
35
  Component extends ComponentPublicInstance<
36
    Props,
37
    RawBindings,
38
    D,
39
    C,
40
    M
41
  > = ComponentPublicInstance<any>,
42
  Props = any,
43
  RawBindings = any,
44
  D = any,
45
  C extends ComputedOptions = ComputedOptions,
46
  M extends MethodOptions = MethodOptions,
47
> = { new (): Component } & ComponentOptions<Props, RawBindings, D, C, M>;
48

49
// https://github.com/vuejs/vue-next/blob/d84d5ecdbdf709570122175d6565bb61fae877f2/packages/runtime-core/src/apiDefineComponent.ts#L29-L31
50
// TODO: This can be imported from vue directly once this PR gets merged: https://github.com/vuejs/vue-next/pull/2403
51
export type PublicProps = VNodeProps &
52
  AllowedComponentProps &
53
  ComponentCustomProps;
54

55
// Can't use `DefineComponent` because of the false prop inferring behavior, it doesn't pick up the required types when an interface is passed
56
// This PR will probably solve the problem as it moves the prop inferring behavior to `defineComponent` function: https://github.com/vuejs/vue-next/pull/4465
57
// GlobalComponentConstructor helper is kind of like the ComponentConstructor type helper, but simpler and keeps the Volar errors simpler,
58
// and also similar to the usage in official Vue packages: https://github.com/vuejs/vue-next/blob/d84d5ecdbdf709570122175d6565bb61fae877f2/packages/runtime-core/src/components/BaseTransition.ts#L258-L264 or https://github.com/vuejs/vue-router-next/blob/5dd5f47515186ce34efb9118dda5aad0bb773439/src/RouterView.ts#L160-L172 etc.
59
// TODO: This can be replaced with `DefineComponent` once this PR gets merged: https://github.com/vuejs/vue-next/pull/4465
60
export type GlobalComponentConstructor<Props = {}, Slots = {}> = {
61
  new (): {
62
    $props: PublicProps & Props;
63
    $slots: Slots;
64
  };
65
};
66

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.