1
- const globalTypes = `
1
+ import { MpxCompilerOptions } from '../../types'
2
+
3
+ const globalTypes = ( ) => `
2
4
// #region DefineComponent - global types
3
5
function DefineComponent<
4
6
D extends Data = {},
@@ -15,7 +17,7 @@ const globalTypes = `
15
17
// #endregion
16
18
17
19
// #region DefinePage - global types
18
- export function DefinePage<
20
+ function DefinePage<
19
21
D extends Data = {},
20
22
P extends Properties = {},
21
23
C = {},
@@ -29,7 +31,7 @@ const globalTypes = `
29
31
// #endregion
30
32
`
31
33
32
- const localTypes = `
34
+ const localTypes = ( lib : MpxCompilerOptions [ 'lib' ] ) => `
33
35
// #region DefineComponent - local types
34
36
type Data = object | (() => object)
35
37
interface Properties {
@@ -122,19 +124,7 @@ type FullPropType<T> = {
122
124
value?: T
123
125
optionalTypes?: WechatMiniprogram.Component.ShortProperty[]
124
126
}
125
- export type PropType<T> = {
126
- __type: T
127
- } & (T extends string
128
- ? StringConstructor
129
- : T extends number
130
- ? NumberConstructor
131
- : T extends boolean
132
- ? BooleanConstructor
133
- : T extends any[]
134
- ? ArrayConstructor
135
- : T extends object
136
- ? ObjectConstructor
137
- : never)
127
+ type PropType = import('${ lib } ').PropType
138
128
type UnboxMixinField<T extends Mixin<{}, {}, {}, {}>, F> = F extends keyof T ? T[F] : {}
139
129
type UnboxMixinsField<Mi extends Array<any>, F> = UnionToIntersection<
140
130
RequiredPropertiesForUnion<UnboxMixinField<ArrayType<Mi>, F>>
@@ -152,7 +142,7 @@ interface Mixin<D, P, C, M> {
152
142
methods?: M
153
143
[index: string]: any
154
144
}
155
- export type ComponentIns<
145
+ type ComponentIns<
156
146
D extends Data = {},
157
147
P extends Properties = {},
158
148
C = {},
@@ -164,18 +154,16 @@ export type ComponentIns<
164
154
UnboxMixinsField<Mi, 'data'> &
165
155
M &
166
156
UnboxMixinsField<Mi, 'methods'> & {
167
- [K in keyof S]: S[K] extends import('@mpxjs/core ').Ref<infer V> ? V : S[K]
157
+ [K in keyof S]: S[K] extends import('${ lib } ').Ref<infer V> ? V : S[K]
168
158
} & GetPropsType<P & UnboxMixinsField<Mi, 'properties'>> &
169
159
GetComputedType<C & UnboxMixinsField<Mi, 'computed'>> &
170
160
WxComponentIns<D, P, M> &
171
161
MpxComponentIns &
172
162
MpxComProps<O>
173
163
type GetDataType<T> = T extends () => any ? ReturnType<T> : T
174
164
type MpxComProps<O> = { $rawOptions: O }
175
- export interface MpxComponentIns {
176
- [k: string]: any
177
- }
178
- export type GetComputedType<T> = {
165
+ type MpxComponentIns = import('${ lib } ').MpxComponentIns
166
+ type GetComputedType<T> = {
179
167
[K in keyof T]: T[K] extends { get: (...args: any[]) => infer R }
180
168
? R
181
169
: T[K] extends (...args: any[]) => infer R
0 commit comments