59 | type Property = Component.Property
60 | type Method = Component.Method
61 |
62 | type DefinitionFilter = Component.DefinitionFilter
63 | type Lifetimes = Component.Lifetimes
64 |
65 | type OtherOption = Omit
66 | }
67 | /** 注册一个 `behavior`,接受一个 `Object` 类型的参数。*/
68 | declare let Behavior: WechatMiniprogram.Behavior.Constructor
69 |
--------------------------------------------------------------------------------
/typings/types/wx/lib.wx.cloud.d.ts:
--------------------------------------------------------------------------------
1 | /*! *****************************************************************************
2 | Copyright (c) 2023 Tencent, Inc. All rights reserved.
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | ***************************************************************************** */
22 |
23 | interface IAPIError {
24 | errMsg: string
25 | }
26 |
27 | interface IAPIParam {
28 | config?: ICloudConfig
29 | success?: (res: T) => void
30 | fail?: (err: IAPIError) => void
31 | complete?: (val: T | IAPIError) => void
32 | }
33 |
34 | interface IAPISuccessParam {
35 | errMsg: string
36 | }
37 |
38 | type IAPICompleteParam = IAPISuccessParam | IAPIError
39 |
40 | type IAPIFunction> = (param?: P) => Promise
41 |
42 | interface IInitCloudConfig {
43 | env?:
44 | | string
45 | | {
46 | database?: string
47 | functions?: string
48 | storage?: string
49 | }
50 | traceUser?: boolean
51 | }
52 |
53 | interface ICloudConfig {
54 | env?: string
55 | traceUser?: boolean
56 | }
57 |
58 | interface IICloudAPI {
59 | init: (config?: IInitCloudConfig) => void
60 | [api: string]: AnyFunction | IAPIFunction
61 | }
62 |
63 | interface ICloudService {
64 | name: string
65 |
66 | getAPIs: () => { [name: string]: IAPIFunction }
67 | }
68 |
69 | interface ICloudServices {
70 | [serviceName: string]: ICloudService
71 | }
72 |
73 | interface ICloudMetaData {
74 | session_id: string
75 | }
76 |
77 | declare class InternalSymbol {}
78 |
79 | interface AnyObject {
80 | [x: string]: any
81 | }
82 |
83 | type AnyArray = any[]
84 |
85 | type AnyFunction = (...args: any[]) => any
86 |
87 | /**
88 | * extend wx with cloud
89 | */
90 | interface WxCloud {
91 | init: (config?: ICloudConfig) => void
92 |
93 | callFunction(param: OQ): void
94 | callFunction(
95 | param: RQ
96 | ): Promise
97 |
98 | uploadFile(param: OQ): WechatMiniprogram.UploadTask
99 | uploadFile(
100 | param: RQ
101 | ): Promise
102 |
103 | downloadFile(
104 | param: OQ
105 | ): WechatMiniprogram.DownloadTask
106 | downloadFile(
107 | param: RQ
108 | ): Promise
109 |
110 | getTempFileURL(param: OQ): void
111 | getTempFileURL(
112 | param: RQ
113 | ): Promise
114 |
115 | deleteFile(param: OQ): void
116 | deleteFile(
117 | param: RQ
118 | ): Promise
119 |
120 | database: (config?: ICloudConfig) => DB.Database
121 |
122 | CloudID: ICloud.ICloudIDConstructor
123 | CDN: ICloud.ICDNConstructor
124 |
125 | callContainer(param: OQ): void
126 | callContainer(
127 | param: RQ
128 | ): Promise
129 |
130 | connectContainer(param: OQ): void
131 | connectContainer(
132 | param: RQ
133 | ): Promise
134 | }
135 |
136 | declare namespace ICloud {
137 | interface ICloudAPIParam extends IAPIParam {
138 | config?: ICloudConfig
139 | }
140 |
141 | // === API: callFunction ===
142 | type CallFunctionData = AnyObject
143 |
144 | interface CallFunctionResult extends IAPISuccessParam {
145 | result: AnyObject | string | undefined
146 | }
147 |
148 | interface CallFunctionParam extends ICloudAPIParam {
149 | name: string
150 | data?: CallFunctionData
151 | slow?: boolean
152 | }
153 | // === end ===
154 |
155 | // === API: container ===
156 | type CallContainerData = AnyObject
157 |
158 | interface CallContainerResult extends IAPISuccessParam {
159 | data: any
160 | statusCode: number
161 | header: Record
162 | callID: string
163 | }
164 |
165 | interface CallContainerParam extends ICloudAPIParam {
166 | path: string
167 | service?: string
168 | method?: string
169 | header?: Record
170 | data?: any // string, object, ArrayBuffer
171 | dataType?: string
172 | responseType?: string
173 | timeout?: number
174 | verbose?: boolean
175 | followRedirect?: boolean
176 | }
177 |
178 | interface ConnectContainerResult extends IAPISuccessParam {
179 | socketTask: WechatMiniprogram.SocketTask
180 | }
181 |
182 | interface ConnectSocketOptions extends IAPIParam {
183 | header?: Record
184 | protocols?: string[]
185 | tcpNoDelay?: boolean
186 | perMessageDeflate?: boolean
187 | timeout?: number
188 | }
189 |
190 | type ConnectContainerParam = Omit<
191 | ConnectSocketOptions,
192 | 'success' | 'fail' | 'complete'
193 | > &
194 | ICloudAPIParam & {
195 | service: string
196 | path?: string
197 | }
198 | // === end ===
199 |
200 | // === API: uploadFile ===
201 | interface UploadFileResult extends IAPISuccessParam {
202 | fileID: string
203 | statusCode: number
204 | }
205 |
206 | interface UploadFileParam extends ICloudAPIParam {
207 | cloudPath: string
208 | filePath: string
209 | header?: AnyObject
210 | }
211 | // === end ===
212 |
213 | // === API: downloadFile ===
214 | interface DownloadFileResult extends IAPISuccessParam {
215 | tempFilePath: string
216 | statusCode: number
217 | }
218 |
219 | interface DownloadFileParam extends ICloudAPIParam {
220 | fileID: string
221 | cloudPath?: string
222 | }
223 | // === end ===
224 |
225 | // === API: getTempFileURL ===
226 | interface GetTempFileURLResult extends IAPISuccessParam {
227 | fileList: GetTempFileURLResultItem[]
228 | }
229 |
230 | interface GetTempFileURLResultItem {
231 | fileID: string
232 | tempFileURL: string
233 | maxAge: number
234 | status: number
235 | errMsg: string
236 | }
237 |
238 | interface GetTempFileURLParam extends ICloudAPIParam {
239 | fileList: string[]
240 | }
241 | // === end ===
242 |
243 | // === API: deleteFile ===
244 | interface DeleteFileResult extends IAPISuccessParam {
245 | fileList: DeleteFileResultItem[]
246 | }
247 |
248 | interface DeleteFileResultItem {
249 | fileID: string
250 | status: number
251 | errMsg: string
252 | }
253 |
254 | interface DeleteFileParam extends ICloudAPIParam {
255 | fileList: string[]
256 | }
257 | // === end ===
258 |
259 | // === API: CloudID ===
260 | abstract class CloudID {
261 | constructor(cloudID: string)
262 | }
263 |
264 | interface ICloudIDConstructor {
265 | new (cloudId: string): CloudID
266 | (cloudId: string): CloudID
267 | }
268 | // === end ===
269 |
270 | // === API: CDN ===
271 | abstract class CDN {
272 | target: string | ArrayBuffer | ICDNFilePathSpec
273 | constructor(target: string | ArrayBuffer | ICDNFilePathSpec)
274 | }
275 |
276 | interface ICDNFilePathSpec {
277 | type: 'filePath'
278 | filePath: string
279 | }
280 |
281 | interface ICDNConstructor {
282 | new (options: string | ArrayBuffer | ICDNFilePathSpec): CDN
283 | (options: string | ArrayBuffer | ICDNFilePathSpec): CDN
284 | }
285 | // === end ===
286 | }
287 |
288 | // === Database ===
289 | declare namespace DB {
290 | /**
291 | * The class of all exposed cloud database instances
292 | */
293 | class Database {
294 | readonly config: ICloudConfig
295 | readonly command: DatabaseCommand
296 | readonly Geo: IGeo
297 | readonly serverDate: () => ServerDate
298 | readonly RegExp: IRegExpConstructor
299 |
300 | private constructor()
301 |
302 | collection(collectionName: string): CollectionReference
303 | }
304 |
305 | class CollectionReference extends Query {
306 | readonly collectionName: string
307 |
308 | private constructor(name: string, database: Database)
309 |
310 | doc(docId: string | number): DocumentReference
311 |
312 | add(options: OQ): void
313 | add(options: RQ): Promise
314 | }
315 |
316 | class DocumentReference {
317 | private constructor(docId: string | number, database: Database)
318 |
319 | field(object: Record): this
320 |
321 | get(options: OQ): void
322 | get(options?: RQ): Promise
323 |
324 | set(options: OQ): void
325 | set(options?: RQ): Promise
326 |
327 | update(options: OQ): void
328 | update(
329 | options?: RQ
330 | ): Promise
331 |
332 | remove(options: OQ): void
333 | remove(
334 | options?: RQ
335 | ): Promise
336 |
337 | watch(options: IWatchOptions): RealtimeListener
338 | }
339 |
340 | class RealtimeListener {
341 | // "And Now His Watch Is Ended"
342 | close: () => Promise
343 | }
344 |
345 | class Query {
346 | where(condition: IQueryCondition): Query
347 |
348 | orderBy(fieldPath: string, order: string): Query
349 |
350 | limit(max: number): Query
351 |
352 | skip(offset: number): Query
353 |
354 | field(object: Record): Query
355 |
356 | get(options: OQ): void
357 | get(options?: RQ): Promise
358 |
359 | count(options: OQ): void
360 | count(options?: RQ): Promise
361 |
362 | watch(options: IWatchOptions): RealtimeListener
363 | }
364 |
365 | interface DatabaseCommand {
366 | eq(val: any): DatabaseQueryCommand
367 | neq(val: any): DatabaseQueryCommand
368 | gt(val: any): DatabaseQueryCommand
369 | gte(val: any): DatabaseQueryCommand
370 | lt(val: any): DatabaseQueryCommand
371 | lte(val: any): DatabaseQueryCommand
372 | in(val: any[]): DatabaseQueryCommand
373 | nin(val: any[]): DatabaseQueryCommand
374 |
375 | geoNear(options: IGeoNearCommandOptions): DatabaseQueryCommand
376 | geoWithin(options: IGeoWithinCommandOptions): DatabaseQueryCommand
377 | geoIntersects(
378 | options: IGeoIntersectsCommandOptions
379 | ): DatabaseQueryCommand
380 |
381 | and(
382 | ...expressions: Array
383 | ): DatabaseLogicCommand
384 | or(
385 | ...expressions: Array
386 | ): DatabaseLogicCommand
387 | nor(
388 | ...expressions: Array
389 | ): DatabaseLogicCommand
390 | not(expression: DatabaseLogicCommand): DatabaseLogicCommand
391 |
392 | exists(val: boolean): DatabaseQueryCommand
393 |
394 | mod(divisor: number, remainder: number): DatabaseQueryCommand
395 |
396 | all(val: any[]): DatabaseQueryCommand
397 | elemMatch(val: any): DatabaseQueryCommand
398 | size(val: number): DatabaseQueryCommand
399 |
400 | set(val: any): DatabaseUpdateCommand
401 | remove(): DatabaseUpdateCommand
402 | inc(val: number): DatabaseUpdateCommand
403 | mul(val: number): DatabaseUpdateCommand
404 | min(val: number): DatabaseUpdateCommand
405 | max(val: number): DatabaseUpdateCommand
406 | rename(val: string): DatabaseUpdateCommand
407 | bit(val: number): DatabaseUpdateCommand
408 |
409 | push(...values: any[]): DatabaseUpdateCommand
410 | pop(): DatabaseUpdateCommand
411 | shift(): DatabaseUpdateCommand
412 | unshift(...values: any[]): DatabaseUpdateCommand
413 | addToSet(val: any): DatabaseUpdateCommand
414 | pull(val: any): DatabaseUpdateCommand
415 | pullAll(val: any): DatabaseUpdateCommand
416 |
417 | project: {
418 | slice(val: number | [number, number]): DatabaseProjectionCommand
419 | }
420 |
421 | aggregate: {
422 | __safe_props__?: Set
423 |
424 | abs(val: any): DatabaseAggregateCommand
425 | add(val: any): DatabaseAggregateCommand
426 | addToSet(val: any): DatabaseAggregateCommand
427 | allElementsTrue(val: any): DatabaseAggregateCommand
428 | and(val: any): DatabaseAggregateCommand
429 | anyElementTrue(val: any): DatabaseAggregateCommand
430 | arrayElemAt(val: any): DatabaseAggregateCommand
431 | arrayToObject(val: any): DatabaseAggregateCommand
432 | avg(val: any): DatabaseAggregateCommand
433 | ceil(val: any): DatabaseAggregateCommand
434 | cmp(val: any): DatabaseAggregateCommand
435 | concat(val: any): DatabaseAggregateCommand
436 | concatArrays(val: any): DatabaseAggregateCommand
437 | cond(val: any): DatabaseAggregateCommand
438 | convert(val: any): DatabaseAggregateCommand
439 | dateFromParts(val: any): DatabaseAggregateCommand
440 | dateToParts(val: any): DatabaseAggregateCommand
441 | dateFromString(val: any): DatabaseAggregateCommand
442 | dateToString(val: any): DatabaseAggregateCommand
443 | dayOfMonth(val: any): DatabaseAggregateCommand
444 | dayOfWeek(val: any): DatabaseAggregateCommand
445 | dayOfYear(val: any): DatabaseAggregateCommand
446 | divide(val: any): DatabaseAggregateCommand
447 | eq(val: any): DatabaseAggregateCommand
448 | exp(val: any): DatabaseAggregateCommand
449 | filter(val: any): DatabaseAggregateCommand
450 | first(val: any): DatabaseAggregateCommand
451 | floor(val: any): DatabaseAggregateCommand
452 | gt(val: any): DatabaseAggregateCommand
453 | gte(val: any): DatabaseAggregateCommand
454 | hour(val: any): DatabaseAggregateCommand
455 | ifNull(val: any): DatabaseAggregateCommand
456 | in(val: any): DatabaseAggregateCommand
457 | indexOfArray(val: any): DatabaseAggregateCommand
458 | indexOfBytes(val: any): DatabaseAggregateCommand
459 | indexOfCP(val: any): DatabaseAggregateCommand
460 | isArray(val: any): DatabaseAggregateCommand
461 | isoDayOfWeek(val: any): DatabaseAggregateCommand
462 | isoWeek(val: any): DatabaseAggregateCommand
463 | isoWeekYear(val: any): DatabaseAggregateCommand
464 | last(val: any): DatabaseAggregateCommand
465 | let(val: any): DatabaseAggregateCommand
466 | literal(val: any): DatabaseAggregateCommand
467 | ln(val: any): DatabaseAggregateCommand
468 | log(val: any): DatabaseAggregateCommand
469 | log10(val: any): DatabaseAggregateCommand
470 | lt(val: any): DatabaseAggregateCommand
471 | lte(val: any): DatabaseAggregateCommand
472 | ltrim(val: any): DatabaseAggregateCommand
473 | map(val: any): DatabaseAggregateCommand
474 | max(val: any): DatabaseAggregateCommand
475 | mergeObjects(val: any): DatabaseAggregateCommand
476 | meta(val: any): DatabaseAggregateCommand
477 | min(val: any): DatabaseAggregateCommand
478 | millisecond(val: any): DatabaseAggregateCommand
479 | minute(val: any): DatabaseAggregateCommand
480 | mod(val: any): DatabaseAggregateCommand
481 | month(val: any): DatabaseAggregateCommand
482 | multiply(val: any): DatabaseAggregateCommand
483 | neq(val: any): DatabaseAggregateCommand
484 | not(val: any): DatabaseAggregateCommand
485 | objectToArray(val: any): DatabaseAggregateCommand
486 | or(val: any): DatabaseAggregateCommand
487 | pow(val: any): DatabaseAggregateCommand
488 | push(val: any): DatabaseAggregateCommand
489 | range(val: any): DatabaseAggregateCommand
490 | reduce(val: any): DatabaseAggregateCommand
491 | reverseArray(val: any): DatabaseAggregateCommand
492 | rtrim(val: any): DatabaseAggregateCommand
493 | second(val: any): DatabaseAggregateCommand
494 | setDifference(val: any): DatabaseAggregateCommand
495 | setEquals(val: any): DatabaseAggregateCommand
496 | setIntersection(val: any): DatabaseAggregateCommand
497 | setIsSubset(val: any): DatabaseAggregateCommand
498 | setUnion(val: any): DatabaseAggregateCommand
499 | size(val: any): DatabaseAggregateCommand
500 | slice(val: any): DatabaseAggregateCommand
501 | split(val: any): DatabaseAggregateCommand
502 | sqrt(val: any): DatabaseAggregateCommand
503 | stdDevPop(val: any): DatabaseAggregateCommand
504 | stdDevSamp(val: any): DatabaseAggregateCommand
505 | strcasecmp(val: any): DatabaseAggregateCommand
506 | strLenBytes(val: any): DatabaseAggregateCommand
507 | strLenCP(val: any): DatabaseAggregateCommand
508 | substr(val: any): DatabaseAggregateCommand
509 | substrBytes(val: any): DatabaseAggregateCommand
510 | substrCP(val: any): DatabaseAggregateCommand
511 | subtract(val: any): DatabaseAggregateCommand
512 | sum(val: any): DatabaseAggregateCommand
513 | switch(val: any): DatabaseAggregateCommand
514 | toBool(val: any): DatabaseAggregateCommand
515 | toDate(val: any): DatabaseAggregateCommand
516 | toDecimal(val: any): DatabaseAggregateCommand
517 | toDouble(val: any): DatabaseAggregateCommand
518 | toInt(val: any): DatabaseAggregateCommand
519 | toLong(val: any): DatabaseAggregateCommand
520 | toObjectId(val: any): DatabaseAggregateCommand
521 | toString(val: any): DatabaseAggregateCommand
522 | toLower(val: any): DatabaseAggregateCommand
523 | toUpper(val: any): DatabaseAggregateCommand
524 | trim(val: any): DatabaseAggregateCommand
525 | trunc(val: any): DatabaseAggregateCommand
526 | type(val: any): DatabaseAggregateCommand
527 | week(val: any): DatabaseAggregateCommand
528 | year(val: any): DatabaseAggregateCommand
529 | zip(val: any): DatabaseAggregateCommand
530 | }
531 | }
532 |
533 | class DatabaseAggregateCommand {}
534 |
535 | enum LOGIC_COMMANDS_LITERAL {
536 | AND = 'and',
537 | OR = 'or',
538 | NOT = 'not',
539 | NOR = 'nor'
540 | }
541 |
542 | class DatabaseLogicCommand {
543 | and(...expressions: DatabaseLogicCommand[]): DatabaseLogicCommand
544 | or(...expressions: DatabaseLogicCommand[]): DatabaseLogicCommand
545 | nor(...expressions: DatabaseLogicCommand[]): DatabaseLogicCommand
546 | not(expression: DatabaseLogicCommand): DatabaseLogicCommand
547 | }
548 |
549 | enum QUERY_COMMANDS_LITERAL {
550 | // comparison
551 | EQ = 'eq',
552 | NEQ = 'neq',
553 | GT = 'gt',
554 | GTE = 'gte',
555 | LT = 'lt',
556 | LTE = 'lte',
557 | IN = 'in',
558 | NIN = 'nin',
559 | // geo
560 | GEO_NEAR = 'geoNear',
561 | GEO_WITHIN = 'geoWithin',
562 | GEO_INTERSECTS = 'geoIntersects',
563 | // element
564 | EXISTS = 'exists',
565 | // evaluation
566 | MOD = 'mod',
567 | // array
568 | ALL = 'all',
569 | ELEM_MATCH = 'elemMatch',
570 | SIZE = 'size'
571 | }
572 |
573 | class DatabaseQueryCommand extends DatabaseLogicCommand {
574 | eq(val: any): DatabaseLogicCommand
575 | neq(val: any): DatabaseLogicCommand
576 | gt(val: any): DatabaseLogicCommand
577 | gte(val: any): DatabaseLogicCommand
578 | lt(val: any): DatabaseLogicCommand
579 | lte(val: any): DatabaseLogicCommand
580 | in(val: any[]): DatabaseLogicCommand
581 | nin(val: any[]): DatabaseLogicCommand
582 |
583 | exists(val: boolean): DatabaseLogicCommand
584 |
585 | mod(divisor: number, remainder: number): DatabaseLogicCommand
586 |
587 | all(val: any[]): DatabaseLogicCommand
588 | elemMatch(val: any): DatabaseLogicCommand
589 | size(val: number): DatabaseLogicCommand
590 |
591 | geoNear(options: IGeoNearCommandOptions): DatabaseLogicCommand
592 | geoWithin(options: IGeoWithinCommandOptions): DatabaseLogicCommand
593 | geoIntersects(
594 | options: IGeoIntersectsCommandOptions
595 | ): DatabaseLogicCommand
596 | }
597 |
598 | enum PROJECTION_COMMANDS_LITERAL {
599 | SLICE = 'slice'
600 | }
601 |
602 | class DatabaseProjectionCommand {}
603 |
604 | enum UPDATE_COMMANDS_LITERAL {
605 | // field
606 | SET = 'set',
607 | REMOVE = 'remove',
608 | INC = 'inc',
609 | MUL = 'mul',
610 | MIN = 'min',
611 | MAX = 'max',
612 | RENAME = 'rename',
613 | // bitwise
614 | BIT = 'bit',
615 | // array
616 | PUSH = 'push',
617 | POP = 'pop',
618 | SHIFT = 'shift',
619 | UNSHIFT = 'unshift',
620 | ADD_TO_SET = 'addToSet',
621 | PULL = 'pull',
622 | PULL_ALL = 'pullAll'
623 | }
624 |
625 | class DatabaseUpdateCommand {}
626 |
627 | class Batch {}
628 |
629 | /**
630 | * A contract that all API provider must adhere to
631 | */
632 | class APIBaseContract<
633 | PromiseReturn,
634 | CallbackReturn,
635 | Param extends IAPIParam,
636 | Context = any
637 | > {
638 | getContext(param: Param): Context
639 |
640 | /**
641 | * In case of callback-style invocation, this function will be called
642 | */
643 | getCallbackReturn(param: Param, context: Context): CallbackReturn
644 |
645 | getFinalParam(param: Param, context: Context): T
646 |
647 | run(param: T): Promise
648 | }
649 |
650 | interface IGeoPointConstructor {
651 | new (longitude: number, latitide: number): GeoPoint
652 | new (geojson: IGeoJSONPoint): GeoPoint
653 | (longitude: number, latitide: number): GeoPoint
654 | (geojson: IGeoJSONPoint): GeoPoint
655 | }
656 |
657 | interface IGeoMultiPointConstructor {
658 | new (points: GeoPoint[] | IGeoJSONMultiPoint): GeoMultiPoint
659 | (points: GeoPoint[] | IGeoJSONMultiPoint): GeoMultiPoint
660 | }
661 |
662 | interface IGeoLineStringConstructor {
663 | new (points: GeoPoint[] | IGeoJSONLineString): GeoLineString
664 | (points: GeoPoint[] | IGeoJSONLineString): GeoLineString
665 | }
666 |
667 | interface IGeoMultiLineStringConstructor {
668 | new (
669 | lineStrings: GeoLineString[] | IGeoJSONMultiLineString
670 | ): GeoMultiLineString
671 | (
672 | lineStrings: GeoLineString[] | IGeoJSONMultiLineString
673 | ): GeoMultiLineString
674 | }
675 |
676 | interface IGeoPolygonConstructor {
677 | new (lineStrings: GeoLineString[] | IGeoJSONPolygon): GeoPolygon
678 | (lineStrings: GeoLineString[] | IGeoJSONPolygon): GeoPolygon
679 | }
680 |
681 | interface IGeoMultiPolygonConstructor {
682 | new (polygons: GeoPolygon[] | IGeoJSONMultiPolygon): GeoMultiPolygon
683 | (polygons: GeoPolygon[] | IGeoJSONMultiPolygon): GeoMultiPolygon
684 | }
685 |
686 | interface IGeo {
687 | Point: IGeoPointConstructor
688 | MultiPoint: IGeoMultiPointConstructor
689 | LineString: IGeoLineStringConstructor
690 | MultiLineString: IGeoMultiLineStringConstructor
691 | Polygon: IGeoPolygonConstructor
692 | MultiPolygon: IGeoMultiPolygonConstructor
693 | }
694 |
695 | interface IGeoJSONPoint {
696 | type: 'Point'
697 | coordinates: [number, number]
698 | }
699 |
700 | interface IGeoJSONMultiPoint {
701 | type: 'MultiPoint'
702 | coordinates: Array<[number, number]>
703 | }
704 |
705 | interface IGeoJSONLineString {
706 | type: 'LineString'
707 | coordinates: Array<[number, number]>
708 | }
709 |
710 | interface IGeoJSONMultiLineString {
711 | type: 'MultiLineString'
712 | coordinates: Array>
713 | }
714 |
715 | interface IGeoJSONPolygon {
716 | type: 'Polygon'
717 | coordinates: Array>
718 | }
719 |
720 | interface IGeoJSONMultiPolygon {
721 | type: 'MultiPolygon'
722 | coordinates: Array>>
723 | }
724 |
725 | type IGeoJSONObject =
726 | | IGeoJSONPoint
727 | | IGeoJSONMultiPoint
728 | | IGeoJSONLineString
729 | | IGeoJSONMultiLineString
730 | | IGeoJSONPolygon
731 | | IGeoJSONMultiPolygon
732 |
733 | abstract class GeoPoint {
734 | longitude: number
735 | latitude: number
736 |
737 | constructor(longitude: number, latitude: number)
738 |
739 | toJSON(): Record
740 | toString(): string
741 | }
742 |
743 | abstract class GeoMultiPoint {
744 | points: GeoPoint[]
745 |
746 | constructor(points: GeoPoint[])
747 |
748 | toJSON(): IGeoJSONMultiPoint
749 | toString(): string
750 | }
751 |
752 | abstract class GeoLineString {
753 | points: GeoPoint[]
754 |
755 | constructor(points: GeoPoint[])
756 |
757 | toJSON(): IGeoJSONLineString
758 | toString(): string
759 | }
760 |
761 | abstract class GeoMultiLineString {
762 | lines: GeoLineString[]
763 |
764 | constructor(lines: GeoLineString[])
765 |
766 | toJSON(): IGeoJSONMultiLineString
767 | toString(): string
768 | }
769 |
770 | abstract class GeoPolygon {
771 | lines: GeoLineString[]
772 |
773 | constructor(lines: GeoLineString[])
774 |
775 | toJSON(): IGeoJSONPolygon
776 | toString(): string
777 | }
778 |
779 | abstract class GeoMultiPolygon {
780 | polygons: GeoPolygon[]
781 |
782 | constructor(polygons: GeoPolygon[])
783 |
784 | toJSON(): IGeoJSONMultiPolygon
785 | toString(): string
786 | }
787 |
788 | type GeoInstance =
789 | | GeoPoint
790 | | GeoMultiPoint
791 | | GeoLineString
792 | | GeoMultiLineString
793 | | GeoPolygon
794 | | GeoMultiPolygon
795 |
796 | interface IGeoNearCommandOptions {
797 | geometry: GeoPoint
798 | maxDistance?: number
799 | minDistance?: number
800 | }
801 |
802 | interface IGeoWithinCommandOptions {
803 | geometry: GeoPolygon | GeoMultiPolygon
804 | }
805 |
806 | interface IGeoIntersectsCommandOptions {
807 | geometry:
808 | | GeoPoint
809 | | GeoMultiPoint
810 | | GeoLineString
811 | | GeoMultiLineString
812 | | GeoPolygon
813 | | GeoMultiPolygon
814 | }
815 |
816 | interface IServerDateOptions {
817 | offset: number
818 | }
819 |
820 | abstract class ServerDate {
821 | readonly options: IServerDateOptions
822 | constructor(options?: IServerDateOptions)
823 | }
824 |
825 | interface IRegExpOptions {
826 | regexp: string
827 | options?: string
828 | }
829 |
830 | interface IRegExpConstructor {
831 | new (options: IRegExpOptions): RegExp
832 | (options: IRegExpOptions): RegExp
833 | }
834 |
835 | abstract class RegExp {
836 | readonly regexp: string
837 | readonly options: string
838 | constructor(options: IRegExpOptions)
839 | }
840 |
841 | type DocumentId = string | number
842 |
843 | interface IDocumentData {
844 | _id?: DocumentId
845 | [key: string]: any
846 | }
847 |
848 | type IDBAPIParam = IAPIParam
849 |
850 | interface IAddDocumentOptions extends IDBAPIParam {
851 | data: IDocumentData
852 | }
853 |
854 | type IGetDocumentOptions = IDBAPIParam
855 |
856 | type ICountDocumentOptions = IDBAPIParam
857 |
858 | interface IUpdateDocumentOptions extends IDBAPIParam {
859 | data: IUpdateCondition
860 | }
861 |
862 | interface IUpdateSingleDocumentOptions extends IDBAPIParam {
863 | data: IUpdateCondition
864 | }
865 |
866 | interface ISetDocumentOptions extends IDBAPIParam {
867 | data: IUpdateCondition
868 | }
869 |
870 | interface ISetSingleDocumentOptions extends IDBAPIParam {
871 | data: IUpdateCondition
872 | }
873 |
874 | interface IRemoveDocumentOptions extends IDBAPIParam {
875 | query: IQueryCondition
876 | }
877 |
878 | type IRemoveSingleDocumentOptions = IDBAPIParam
879 |
880 | interface IWatchOptions {
881 | // server realtime data init & change event
882 | onChange: (snapshot: ISnapshot) => void
883 | // error while connecting / listening
884 | onError: (error: any) => void
885 | }
886 |
887 | interface ISnapshot {
888 | id: number
889 | docChanges: ISingleDBEvent[]
890 | docs: Record
891 | type?: SnapshotType
892 | }
893 |
894 | type SnapshotType = 'init'
895 |
896 | interface ISingleDBEvent {
897 | id: number
898 | dataType: DataType
899 | queueType: QueueType
900 | docId: string
901 | doc: Record
902 | updatedFields?: Record
903 | removedFields?: string[]
904 | }
905 |
906 | type DataType = 'init' | 'update' | 'replace' | 'add' | 'remove' | 'limit'
907 |
908 | type QueueType = 'init' | 'enqueue' | 'dequeue' | 'update'
909 |
910 | interface IQueryCondition {
911 | [key: string]: any
912 | }
913 |
914 | type IStringQueryCondition = string
915 |
916 | interface IQueryResult extends IAPISuccessParam {
917 | data: IDocumentData[]
918 | }
919 |
920 | interface IQuerySingleResult extends IAPISuccessParam {
921 | data: IDocumentData
922 | }
923 |
924 | interface IUpdateCondition {
925 | [key: string]: any
926 | }
927 |
928 | type IStringUpdateCondition = string
929 |
930 | interface IAddResult extends IAPISuccessParam {
931 | _id: DocumentId
932 | }
933 |
934 | interface IUpdateResult extends IAPISuccessParam {
935 | stats: {
936 | updated: number
937 | // created: number,
938 | }
939 | }
940 |
941 | interface ISetResult extends IAPISuccessParam {
942 | _id: DocumentId
943 | stats: {
944 | updated: number
945 | created: number
946 | }
947 | }
948 |
949 | interface IRemoveResult extends IAPISuccessParam {
950 | stats: {
951 | removed: number
952 | }
953 | }
954 |
955 | interface ICountResult extends IAPISuccessParam {
956 | total: number
957 | }
958 | }
959 |
960 | type Optional = { [K in keyof T]+?: T[K] }
961 |
962 | type OQ<
963 | T extends Optional<
964 | Record<'complete' | 'success' | 'fail', (...args: any[]) => any>
965 | >
966 | > =
967 | | (RQ & Required>)
968 | | (RQ & Required>)
969 | | (RQ & Required>)
970 | | (RQ & Required>)
971 | | (RQ & Required>)
972 | | (RQ & Required>)
973 | | (RQ & Required>)
974 |
975 | type RQ<
976 | T extends Optional<
977 | Record<'complete' | 'success' | 'fail', (...args: any[]) => any>
978 | >
979 | > = Pick>
980 |
--------------------------------------------------------------------------------
/typings/types/wx/lib.wx.component.d.ts:
--------------------------------------------------------------------------------
1 | /*! *****************************************************************************
2 | Copyright (c) 2023 Tencent, Inc. All rights reserved.
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | ***************************************************************************** */
22 |
23 | declare namespace WechatMiniprogram.Component {
24 | type Instance<
25 | TData extends DataOption,
26 | TProperty extends PropertyOption,
27 | TMethod extends Partial,
28 | TCustomInstanceProperty extends IAnyObject = {},
29 | TIsPage extends boolean = false
30 | > = InstanceProperties &
31 | InstanceMethods &
32 | TMethod &
33 | (TIsPage extends true ? Page.ILifetime : {}) &
34 | TCustomInstanceProperty & {
35 | /** 组件数据,**包括内部数据和属性值** */
36 | data: TData & PropertyOptionToData
37 | /** 组件数据,**包括内部数据和属性值**(与 `data` 一致) */
38 | properties: TData & PropertyOptionToData
39 | }
40 | type TrivialInstance = Instance<
41 | IAnyObject,
42 | IAnyObject,
43 | IAnyObject,
44 | IAnyObject
45 | >
46 | type TrivialOption = Options
47 | type Options<
48 | TData extends DataOption,
49 | TProperty extends PropertyOption,
50 | TMethod extends MethodOption,
51 | TCustomInstanceProperty extends IAnyObject = {},
52 | TIsPage extends boolean = false
53 | > = Partial> &
54 | Partial> &
55 | Partial> &
56 | Partial &
57 | Partial &
58 | ThisType<
59 | Instance<
60 | TData,
61 | TProperty,
62 | TMethod,
63 | TCustomInstanceProperty,
64 | TIsPage
65 | >
66 | >
67 | interface Constructor {
68 | <
69 | TData extends DataOption,
70 | TProperty extends PropertyOption,
71 | TMethod extends MethodOption,
72 | TCustomInstanceProperty extends IAnyObject = {},
73 | TIsPage extends boolean = false
74 | >(
75 | options: Options<
76 | TData,
77 | TProperty,
78 | TMethod,
79 | TCustomInstanceProperty,
80 | TIsPage
81 | >
82 | ): string
83 | }
84 | type DataOption = Record
85 | type PropertyOption = Record
86 | type MethodOption = Record
87 |
88 | interface Data {
89 | /** 组件的内部数据,和 `properties` 一同用于组件的模板渲染 */
90 | data?: D
91 | }
92 | interface Property {
93 | /** 组件的对外属性,是属性名到属性设置的映射表 */
94 | properties: P
95 | }
96 | interface Method {
97 | /** 组件的方法,包括事件响应函数和任意的自定义方法,关于事件响应函数的使用,参见 [组件间通信与事件](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/events.html) */
98 | methods: M & (TIsPage extends true ? Partial : {})
99 | }
100 | type PropertyType =
101 | | StringConstructor
102 | | NumberConstructor
103 | | BooleanConstructor
104 | | ArrayConstructor
105 | | ObjectConstructor
106 | | null
107 | type ValueType = T extends null
108 | ? any
109 | : T extends StringConstructor
110 | ? string
111 | : T extends NumberConstructor
112 | ? number
113 | : T extends BooleanConstructor
114 | ? boolean
115 | : T extends ArrayConstructor
116 | ? any[]
117 | : T extends ObjectConstructor
118 | ? IAnyObject
119 | : never
120 | type FullProperty = {
121 | /** 属性类型 */
122 | type: T
123 | /** 属性初始值 */
124 | value?: ValueType
125 | /** 属性值被更改时的响应函数 */
126 | observer?:
127 | | string
128 | | ((
129 | newVal: ValueType,
130 | oldVal: ValueType,
131 | changedPath: Array
132 | ) => void)
133 | /** 属性的类型(可以指定多个) */
134 | optionalTypes?: ShortProperty[]
135 | }
136 | type AllFullProperty =
137 | | FullProperty
138 | | FullProperty
139 | | FullProperty
140 | | FullProperty
141 | | FullProperty
142 | | FullProperty
143 | type ShortProperty =
144 | | StringConstructor
145 | | NumberConstructor
146 | | BooleanConstructor
147 | | ArrayConstructor
148 | | ObjectConstructor
149 | | null
150 | type AllProperty = AllFullProperty | ShortProperty
151 | type PropertyToData = T extends ShortProperty
152 | ? ValueType
153 | : FullPropertyToData>
154 | type FullPropertyToData = ValueType
155 | // type FullPropertyToData = unknown extends T['value'] ? ValueType : T['value']
156 | type PropertyOptionToData = {
157 | [name in keyof P]: PropertyToData
158 | }
159 |
160 | interface InstanceProperties {
161 | /** 组件的文件路径 */
162 | is: string
163 | /** 节点id */
164 | id: string
165 | /** 节点dataset */
166 | dataset: Record
167 | }
168 |
169 | interface InstanceMethods {
170 | /** `setData` 函数用于将数据从逻辑层发送到视图层
171 | *(异步),同时改变对应的 `this.data` 的值(同步)。
172 | *
173 | * **注意:**
174 | *
175 | * 1. **直接修改 this.data 而不调用 this.setData 是无法改变页面的状态的,还会造成数据不一致**。
176 | * 1. 仅支持设置可 JSON 化的数据。
177 | * 1. 单次设置的数据不能超过1024kB,请尽量避免一次设置过多的数据。
178 | * 1. 请不要把 data 中任何一项的 value 设为 `undefined` ,否则这一项将不被设置并可能遗留一些潜在问题。
179 | */
180 | setData(
181 | /** 这次要改变的数据
182 | *
183 | * 以 `key: value` 的形式表示,将 `this.data` 中的 `key` 对应的值改变成 `value`。
184 | *
185 | * 其中 `key` 可以以数据路径的形式给出,支持改变数组中的某一项或对象的某个属性,如 `array[2].message`,`a.b.c.d`,并且不需要在 this.data 中预先定义。
186 | */
187 | data: Partial & IAnyObject,
188 | /** setData引起的界面更新渲染完毕后的回调函数,最低基础库: `1.5.0` */
189 | callback?: () => void
190 | ): void
191 |
192 | /** 检查组件是否具有 `behavior` (检查时会递归检查被直接或间接引入的所有behavior) */
193 | hasBehavior(behavior: Behavior.BehaviorIdentifier): void
194 | /** 触发事件,参见组件事件 */
195 | triggerEvent(
196 | name: string,
197 | detail?: DetailType,
198 | options?: TriggerEventOption
199 | ): void
200 | /** 创建一个 SelectorQuery 对象,选择器选取范围为这个组件实例内 */
201 | createSelectorQuery(): SelectorQuery
202 | /** 创建一个 IntersectionObserver 对象,选择器选取范围为这个组件实例内 */
203 | createIntersectionObserver(
204 | options: CreateIntersectionObserverOption
205 | ): IntersectionObserver
206 | /** 使用选择器选择组件实例节点,返回匹配到的第一个组件实例对象(会被 `wx://component-export` 影响) */
207 | selectComponent(selector: string): TrivialInstance
208 | /** 使用选择器选择组件实例节点,返回匹配到的全部组件实例对象组成的数组 */
209 | selectAllComponents(selector: string): TrivialInstance[]
210 | /**
211 | * 选取当前组件节点所在的组件实例(即组件的引用者),返回它的组件实例对象(会被 `wx://component-export` 影响)
212 | *
213 | * 最低基础库版本:[`2.8.2`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
214 | **/
215 | selectOwnerComponent(): TrivialInstance
216 | /** 获取这个关系所对应的所有关联节点,参见 组件间关系 */
217 | getRelationNodes(relationKey: string): TrivialInstance[]
218 | /**
219 | * 立刻执行 callback ,其中的多个 setData 之间不会触发界面绘制(只有某些特殊场景中需要,如用于在不同组件同时 setData 时进行界面绘制同步)
220 | *
221 | * 最低基础库版本:[`2.4.0`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
222 | **/
223 | groupSetData(callback?: () => void): void
224 | /**
225 | * 返回当前页面的 custom-tab-bar 的组件实例
226 | *
227 | * 最低基础库版本:[`2.6.2`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
228 | **/
229 | getTabBar(): TrivialInstance
230 | /**
231 | * 返回页面标识符(一个字符串),可以用来判断几个自定义组件实例是不是在同一个页面内
232 | *
233 | * 最低基础库版本:[`2.7.1`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
234 | **/
235 | getPageId(): string
236 | /**
237 | * 执行关键帧动画,详见[动画](https://developers.weixin.qq.com/miniprogram/dev/framework/view/animation.html)
238 | *
239 | * 最低基础库版本:[`2.9.0`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
240 | **/
241 | animate(
242 | selector: string,
243 | keyFrames: KeyFrame[],
244 | duration: number,
245 | callback?: () => void
246 | ): void
247 | /**
248 | * 执行关键帧动画,详见[动画](https://developers.weixin.qq.com/miniprogram/dev/framework/view/animation.html)
249 | *
250 | * 最低基础库版本:[`2.9.0`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
251 | **/
252 | animate(
253 | selector: string,
254 | keyFrames: ScrollTimelineKeyframe[],
255 | duration: number,
256 | scrollTimeline: ScrollTimelineOption
257 | ): void
258 | /**
259 | * 清除关键帧动画,详见[动画](https://developers.weixin.qq.com/miniprogram/dev/framework/view/animation.html)
260 | *
261 | * 最低基础库版本:[`2.9.0`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
262 | **/
263 | clearAnimation(selector: string, callback: () => void): void
264 | /**
265 | * 清除关键帧动画,详见[动画](https://developers.weixin.qq.com/miniprogram/dev/framework/view/animation.html)
266 | *
267 | * 最低基础库版本:[`2.9.0`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
268 | **/
269 | clearAnimation(
270 | selector: string,
271 | options?: ClearAnimationOptions,
272 | callback?: () => void
273 | ): void
274 | /**
275 | * 当从另一页面跳转到该页面时,获得与来源页面实例通信当事件通道,详见 [wx.navigateTo]((wx.navigateTo))
276 | *
277 | * 最低基础库版本:[`2.7.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
278 | */
279 | getOpenerEventChannel(): EventChannel
280 | /**
281 | * 获取更新性能统计信息,详见 [获取更新性能统计信息]((custom-component/update-perf-stat))
282 | *
283 | *
284 | * 最低基础库版本:[`2.12.0`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
285 | */
286 | setUpdatePerformanceListener(
287 | options: SetUpdatePerformanceListenerOption,
288 | callback?: UpdatePerformanceListener
289 | ): void
290 | }
291 |
292 | interface ComponentOptions {
293 | /**
294 | * [启用多slot支持](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/wxml-wxss.html#组件wxml的slot)
295 | */
296 | multipleSlots?: boolean
297 | /**
298 | * [组件样式隔离](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/wxml-wxss.html#组件样式隔离)
299 | */
300 | addGlobalClass?: boolean
301 | /**
302 | * [组件样式隔离](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/wxml-wxss.html#组件样式隔离)
303 | */
304 | styleIsolation?:
305 | | 'isolated'
306 | | 'apply-shared'
307 | | 'shared'
308 | | 'page-isolated'
309 | | 'page-apply-shared'
310 | | 'page-shared'
311 | /**
312 | * [纯数据字段](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/pure-data.html) 是一些不用于界面渲染的 data 字段,可以用于提升页面更新性能。从小程序基础库版本 2.8.2 开始支持。
313 | */
314 | pureDataPattern?: RegExp
315 | /**
316 | * [虚拟化组件节点](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/wxml-wxss.html#%E8%99%9A%E6%8B%9F%E5%8C%96%E7%BB%84%E4%BB%B6%E8%8A%82%E7%82%B9) 使自定义组件内部的第一层节点由自定义组件本身完全决定。从小程序基础库版本 [`2.11.2`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html) 开始支持 */
317 | virtualHost?: boolean
318 | }
319 |
320 | interface TriggerEventOption {
321 | /** 事件是否冒泡
322 | *
323 | * 默认值: `false`
324 | */
325 | bubbles?: boolean
326 | /** 事件是否可以穿越组件边界,为false时,事件将只能在引用组件的节点树上触发,不进入其他任何组件内部
327 | *
328 | * 默认值: `false`
329 | */
330 | composed?: boolean
331 | /** 事件是否拥有捕获阶段
332 | *
333 | * 默认值: `false`
334 | */
335 | capturePhase?: boolean
336 | }
337 |
338 | interface RelationOption {
339 | /** 目标组件的相对关系 */
340 | type: 'parent' | 'child' | 'ancestor' | 'descendant'
341 | /** 关系生命周期函数,当关系被建立在页面节点树中时触发,触发时机在组件attached生命周期之后 */
342 | linked?(target: TrivialInstance): void
343 | /** 关系生命周期函数,当关系在页面节点树中发生改变时触发,触发时机在组件moved生命周期之后 */
344 | linkChanged?(target: TrivialInstance): void
345 | /** 关系生命周期函数,当关系脱离页面节点树时触发,触发时机在组件detached生命周期之后 */
346 | unlinked?(target: TrivialInstance): void
347 | /** 如果这一项被设置,则它表示关联的目标节点所应具有的behavior,所有拥有这一behavior的组件节点都会被关联 */
348 | target?: string
349 | }
350 |
351 | interface PageLifetimes {
352 | /** 页面生命周期回调—监听页面显示
353 | *
354 | * 页面显示/切入前台时触发。
355 | */
356 | show(): void
357 | /** 页面生命周期回调—监听页面隐藏
358 | *
359 | * 页面隐藏/切入后台时触发。 如 `navigateTo` 或底部 `tab` 切换到其他页面,小程序切入后台等。
360 | */
361 | hide(): void
362 | /** 页面生命周期回调—监听页面尺寸变化
363 | *
364 | * 所在页面尺寸变化时执行
365 | */
366 | resize(size: Page.IResizeOption): void
367 | }
368 |
369 | type DefinitionFilter = (
370 | /** 使用该 behavior 的 component/behavior 的定义对象 */
371 | defFields: T,
372 | /** 该 behavior 所使用的 behavior 的 definitionFilter 函数列表 */
373 | definitionFilterArr?: DefinitionFilter[]
374 | ) => void
375 |
376 | interface Lifetimes {
377 | /** 组件生命周期声明对象,组件的生命周期:`created`、`attached`、`ready`、`moved`、`detached` 将收归到 `lifetimes` 字段内进行声明,原有声明方式仍旧有效,如同时存在两种声明方式,则 `lifetimes` 字段内声明方式优先级最高
378 | *
379 | * 最低基础库: `2.2.3` */
380 | lifetimes: Partial<{
381 | /**
382 | * 在组件实例刚刚被创建时执行,注意此时不能调用 `setData`
383 | *
384 | * 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
385 | */
386 | created(): void
387 | /**
388 | * 在组件实例进入页面节点树时执行
389 | *
390 | * 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
391 | */
392 | attached(): void
393 | /**
394 | * 在组件在视图层布局完成后执行
395 | *
396 | * 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
397 | */
398 | ready(): void
399 | /**
400 | * 在组件实例被移动到节点树另一个位置时执行
401 | *
402 | * 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
403 | */
404 | moved(): void
405 | /**
406 | * 在组件实例被从页面节点树移除时执行
407 | *
408 | * 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
409 | */
410 | detached(): void
411 | /**
412 | * 每当组件方法抛出错误时执行
413 | *
414 | * 最低基础库版本:[`2.4.1`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
415 | */
416 | error(err: Error): void
417 | }>
418 | /**
419 | * @deprecated 旧式的定义方式,基础库 `2.2.3` 起请在 lifetimes 中定义
420 | *
421 | * 在组件实例刚刚被创建时执行
422 | *
423 | * 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
424 | */
425 | created(): void
426 | /**
427 | * @deprecated 旧式的定义方式,基础库 `2.2.3` 起请在 lifetimes 中定义
428 | *
429 | * 在组件实例进入页面节点树时执行
430 | *
431 | * 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
432 | */
433 | attached(): void
434 | /**
435 | * @deprecated 旧式的定义方式,基础库 `2.2.3` 起请在 lifetimes 中定义
436 | *
437 | * 在组件在视图层布局完成后执行
438 | *
439 | * 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
440 | */
441 | ready(): void
442 | /**
443 | * @deprecated 旧式的定义方式,基础库 `2.2.3` 起请在 lifetimes 中定义
444 | *
445 | * 在组件实例被移动到节点树另一个位置时执行
446 | *
447 | * 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
448 | */
449 | moved(): void
450 | /**
451 | * @deprecated 旧式的定义方式,基础库 `2.2.3` 起请在 lifetimes 中定义
452 | *
453 | * 在组件实例被从页面节点树移除时执行
454 | *
455 | * 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
456 | */
457 | detached(): void
458 | /**
459 | * @deprecated 旧式的定义方式,基础库 `2.2.3` 起请在 lifetimes 中定义
460 | *
461 | * 每当组件方法抛出错误时执行
462 | *
463 | * 最低基础库版本:[`2.4.1`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
464 | */
465 | error(err: Error): void
466 | }
467 |
468 | interface OtherOption {
469 | /** 类似于mixins和traits的组件间代码复用机制,参见 [behaviors](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/behaviors.html) */
470 | behaviors: Behavior.BehaviorIdentifier[]
471 | /**
472 | * 组件数据字段监听器,用于监听 properties 和 data 的变化,参见 [数据监听器](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/observer.html)
473 | *
474 | * 最低基础库版本:[`2.6.1`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
475 | */
476 | observers: Record any>
477 | /** 组件间关系定义,参见 [组件间关系](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/lifetimes.html) */
478 | relations: {
479 | [componentName: string]: RelationOption
480 | }
481 | /** 组件接受的外部样式类,参见 [外部样式类](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/wxml-wxss.html) */
482 | externalClasses?: string[]
483 | /** 组件所在页面的生命周期声明对象,参见 [组件生命周期](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/lifetimes.html)
484 | *
485 | * 最低基础库版本: [`2.2.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html) */
486 | pageLifetimes?: Partial
487 | /** 一些选项(文档中介绍相关特性时会涉及具体的选项设置,这里暂不列举) */
488 | options: ComponentOptions
489 |
490 | /** 定义段过滤器,用于自定义组件扩展,参见 [自定义组件扩展](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/extend.html)
491 | *
492 | * 最低基础库版本: [`2.2.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html) */
493 | definitionFilter?: DefinitionFilter
494 | /**
495 | * 组件自定义导出,当使用 `behavior: wx://component-export` 时,这个定义段可以用于指定组件被 selectComponent 调用时的返回值,参见 [组件间通信与事件](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/events.html)
496 | * 最低基础库版本: [`2.2.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html) */
497 | export: () => IAnyObject
498 | }
499 |
500 | interface KeyFrame {
501 | /** 关键帧的偏移,范围[0-1] */
502 | offset?: number
503 | /** 动画缓动函数 */
504 | ease?: string
505 | /** 基点位置,即 CSS transform-origin */
506 | transformOrigin?: string
507 | /** 背景颜色,即 CSS background-color */
508 | backgroundColor?: string
509 | /** 底边位置,即 CSS bottom */
510 | bottom?: number | string
511 | /** 高度,即 CSS height */
512 | height?: number | string
513 | /** 左边位置,即 CSS left */
514 | left?: number | string
515 | /** 宽度,即 CSS width */
516 | width?: number | string
517 | /** 不透明度,即 CSS opacity */
518 | opacity?: number | string
519 | /** 右边位置,即 CSS right */
520 | right?: number | string
521 | /** 顶边位置,即 CSS top */
522 | top?: number | string
523 | /** 变换矩阵,即 CSS transform matrix */
524 | matrix?: number[]
525 | /** 三维变换矩阵,即 CSS transform matrix3d */
526 | matrix3d?: number[]
527 | /** 旋转,即 CSS transform rotate */
528 | rotate?: number
529 | /** 三维旋转,即 CSS transform rotate3d */
530 | rotate3d?: number[]
531 | /** X 方向旋转,即 CSS transform rotateX */
532 | rotateX?: number
533 | /** Y 方向旋转,即 CSS transform rotateY */
534 | rotateY?: number
535 | /** Z 方向旋转,即 CSS transform rotateZ */
536 | rotateZ?: number
537 | /** 缩放,即 CSS transform scale */
538 | scale?: number[]
539 | /** 三维缩放,即 CSS transform scale3d */
540 | scale3d?: number[]
541 | /** X 方向缩放,即 CSS transform scaleX */
542 | scaleX?: number
543 | /** Y 方向缩放,即 CSS transform scaleY */
544 | scaleY?: number
545 | /** Z 方向缩放,即 CSS transform scaleZ */
546 | scaleZ?: number
547 | /** 倾斜,即 CSS transform skew */
548 | skew?: number[]
549 | /** X 方向倾斜,即 CSS transform skewX */
550 | skewX?: number
551 | /** Y 方向倾斜,即 CSS transform skewY */
552 | skewY?: number
553 | /** 位移,即 CSS transform translate */
554 | translate?: Array
555 | /** 三维位移,即 CSS transform translate3d */
556 | translate3d?: Array
557 | /** X 方向位移,即 CSS transform translateX */
558 | translateX?: number | string
559 | /** Y 方向位移,即 CSS transform translateY */
560 | translateY?: number | string
561 | /** Z 方向位移,即 CSS transform translateZ */
562 | translateZ?: number | string
563 | }
564 | interface ClearAnimationOptions {
565 | /** 基点位置,即 CSS transform-origin */
566 | transformOrigin?: boolean
567 | /** 背景颜色,即 CSS background-color */
568 | backgroundColor?: boolean
569 | /** 底边位置,即 CSS bottom */
570 | bottom?: boolean
571 | /** 高度,即 CSS height */
572 | height?: boolean
573 | /** 左边位置,即 CSS left */
574 | left?: boolean
575 | /** 宽度,即 CSS width */
576 | width?: boolean
577 | /** 不透明度,即 CSS opacity */
578 | opacity?: boolean
579 | /** 右边位置,即 CSS right */
580 | right?: boolean
581 | /** 顶边位置,即 CSS top */
582 | top?: boolean
583 | /** 变换矩阵,即 CSS transform matrix */
584 | matrix?: boolean
585 | /** 三维变换矩阵,即 CSS transform matrix3d */
586 | matrix3d?: boolean
587 | /** 旋转,即 CSS transform rotate */
588 | rotate?: boolean
589 | /** 三维旋转,即 CSS transform rotate3d */
590 | rotate3d?: boolean
591 | /** X 方向旋转,即 CSS transform rotateX */
592 | rotateX?: boolean
593 | /** Y 方向旋转,即 CSS transform rotateY */
594 | rotateY?: boolean
595 | /** Z 方向旋转,即 CSS transform rotateZ */
596 | rotateZ?: boolean
597 | /** 缩放,即 CSS transform scale */
598 | scale?: boolean
599 | /** 三维缩放,即 CSS transform scale3d */
600 | scale3d?: boolean
601 | /** X 方向缩放,即 CSS transform scaleX */
602 | scaleX?: boolean
603 | /** Y 方向缩放,即 CSS transform scaleY */
604 | scaleY?: boolean
605 | /** Z 方向缩放,即 CSS transform scaleZ */
606 | scaleZ?: boolean
607 | /** 倾斜,即 CSS transform skew */
608 | skew?: boolean
609 | /** X 方向倾斜,即 CSS transform skewX */
610 | skewX?: boolean
611 | /** Y 方向倾斜,即 CSS transform skewY */
612 | skewY?: boolean
613 | /** 位移,即 CSS transform translate */
614 | translate?: boolean
615 | /** 三维位移,即 CSS transform translate3d */
616 | translate3d?: boolean
617 | /** X 方向位移,即 CSS transform translateX */
618 | translateX?: boolean
619 | /** Y 方向位移,即 CSS transform translateY */
620 | translateY?: boolean
621 | /** Z 方向位移,即 CSS transform translateZ */
622 | translateZ?: boolean
623 | }
624 | interface ScrollTimelineKeyframe {
625 | composite?: 'replace' | 'add' | 'accumulate' | 'auto'
626 | easing?: string
627 | offset?: number | null
628 | [property: string]: string | number | null | undefined
629 | }
630 | interface ScrollTimelineOption {
631 | /** 指定滚动元素的选择器(只支持 scroll-view),该元素滚动时会驱动动画的进度 */
632 | scrollSource: string
633 | /** 指定滚动的方向。有效值为 horizontal 或 vertical */
634 | orientation?: string
635 | /** 指定开始驱动动画进度的滚动偏移量,单位 px */
636 | startScrollOffset: number
637 | /** 指定停止驱动动画进度的滚动偏移量,单位 px */
638 | endScrollOffset: number
639 | /** 起始和结束的滚动范围映射的时间长度,该时间可用于与关键帧动画里的时间 (duration) 相匹配,单位 ms */
640 | timeRange: number
641 | }
642 |
643 | interface SetUpdatePerformanceListenerOption {
644 | /** 是否返回变更的 data 字段信息 */
645 | withDataPaths?: WithDataPath
646 | }
647 | interface UpdatePerformanceListener {
648 | (res: UpdatePerformance): void
649 | }
650 | interface UpdatePerformance {
651 | /** 此次更新过程的 ID */
652 | updateProcessId: number
653 | /** 对于子更新,返回它所属的更新过程 ID */
654 | parentUpdateProcessId?: number
655 | /** 是否是被合并更新,如果是,则 updateProcessId 表示被合并到的更新过程 ID */
656 | isMergedUpdate: boolean
657 | /** 此次更新的 data 字段信息,只有 withDataPaths 设为 true 时才会返回 */
658 | dataPaths: WithDataPath extends true ? string[] : undefined
659 | /** 此次更新进入等待队列时的时间戳 */
660 | pendingStartTimestamp: number
661 | /** 更新运算开始时的时间戳 */
662 | updateStartTimestamp: number
663 | /** 更新运算结束时的时间戳 */
664 | updateEndTimestamp: number
665 | }
666 | }
667 | /** Component构造器可用于定义组件,调用Component构造器时可以指定组件的属性、数据、方法等。
668 | *
669 | * * 使用 `this.data` 可以获取内部数据和属性值,但不要直接修改它们,应使用 `setData` 修改。
670 | * * 生命周期函数无法在组件方法中通过 `this` 访问到。
671 | * * 属性名应避免以 data 开头,即不要命名成 `dataXyz` 这样的形式,因为在 WXML 中, `data-xyz=""` 会被作为节点 dataset 来处理,而不是组件属性。
672 | * * 在一个组件的定义和使用时,组件的属性名和 data 字段相互间都不能冲突(尽管它们位于不同的定义段中)。
673 | * * 从基础库 `2.0.9` 开始,对象类型的属性和 data 字段中可以包含函数类型的子字段,即可以通过对象类型的属性字段来传递函数。低于这一版本的基础库不支持这一特性。
674 | * * `bug` : 对于 type 为 Object 或 Array 的属性,如果通过该组件自身的 `this.setData` 来改变属性值的一个子字段,则依旧会触发属性 observer ,且 observer 接收到的 `newVal` 是变化的那个子字段的值, `oldVal` 为空, `changedPath` 包含子字段的字段名相关信息。
675 | */
676 | declare let Component: WechatMiniprogram.Component.Constructor
677 |
--------------------------------------------------------------------------------
/typings/types/wx/lib.wx.page.d.ts:
--------------------------------------------------------------------------------
1 | /*! *****************************************************************************
2 | Copyright (c) 2023 Tencent, Inc. All rights reserved.
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | ***************************************************************************** */
22 |
23 | declare namespace WechatMiniprogram.Page {
24 | type Instance<
25 | TData extends DataOption,
26 | TCustom extends CustomOption
27 | > = OptionalInterface &
28 | InstanceProperties &
29 | InstanceMethods &
30 | Data &
31 | TCustom
32 | type Options<
33 | TData extends DataOption,
34 | TCustom extends CustomOption
35 | > = (TCustom &
36 | Partial> &
37 | Partial & {
38 | options?: Component.ComponentOptions
39 | }) &
40 | ThisType>
41 | type TrivialInstance = Instance
42 | interface Constructor {
43 | (
44 | options: Options
45 | ): void
46 | }
47 | interface ILifetime {
48 | /** 生命周期回调—监听页面加载
49 | *
50 | * 页面加载时触发。一个页面只会调用一次,可以在 onLoad 的参数中获取打开当前页面路径中的参数。
51 | */
52 | onLoad(
53 | /** 打开当前页面路径中的参数 */
54 | query: Record
55 | ): void | Promise
56 | /** 生命周期回调—监听页面显示
57 | *
58 | * 页面显示/切入前台时触发。
59 | */
60 | onShow(): void | Promise
61 | /** 生命周期回调—监听页面初次渲染完成
62 | *
63 | * 页面初次渲染完成时触发。一个页面只会调用一次,代表页面已经准备妥当,可以和视图层进行交互。
64 | *
65 |
66 | * 注意:对界面内容进行设置的 API 如`wx.setNavigationBarTitle`,请在`onReady`之后进行。
67 | */
68 | onReady(): void | Promise
69 | /** 生命周期回调—监听页面隐藏
70 | *
71 | * 页面隐藏/切入后台时触发。 如 `navigateTo` 或底部 `tab` 切换到其他页面,小程序切入后台等。
72 | */
73 | onHide(): void | Promise
74 | /** 生命周期回调—监听页面卸载
75 | *
76 | * 页面卸载时触发。如`redirectTo`或`navigateBack`到其他页面时。
77 | */
78 | onUnload(): void | Promise
79 | /** 监听用户下拉动作
80 | *
81 | * 监听用户下拉刷新事件。
82 | * - 需要在`app.json`的`window`选项中或页面配置中开启`enablePullDownRefresh`。
83 | * - 可以通过`wx.startPullDownRefresh`触发下拉刷新,调用后触发下拉刷新动画,效果与用户手动下拉刷新一致。
84 | * - 当处理完数据刷新后,`wx.stopPullDownRefresh`可以停止当前页面的下拉刷新。
85 | */
86 | onPullDownRefresh(): void | Promise
87 | /** 页面上拉触底事件的处理函数
88 | *
89 | * 监听用户上拉触底事件。
90 | * - 可以在`app.json`的`window`选项中或页面配置中设置触发距离`onReachBottomDistance`。
91 | * - 在触发距离内滑动期间,本事件只会被触发一次。
92 | */
93 | onReachBottom(): void | Promise
94 | /** 用户点击右上角转发
95 | *
96 | * 监听用户点击页面内转发按钮(`