Skip to content

Commit 912c19c

Browse files
authored
Add TypeScript types for observer parameters. (#5359)
- PolymerDeepPropertyChange for .* observers. - PolymerSpliceChange and PolymerSplice for .splices observers. - Parameterized for the property/path types. - Matches the name of the interfaces in polymer-externs.js.
1 parent 4f11628 commit 912c19c

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

interfaces.d.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,47 @@ export type BehaviorInit = Pick<
4848
Exclude<keyof PolymerInit, "is" | "extends" | "_template">
4949
>;
5050

51+
/**
52+
* The object passed to ".*" wildcard obsevers. A record of a change made to an
53+
* object.
54+
* @template B The object matching the non-wildcard portion of the path.
55+
* @template V Additional types that could be set at the path.
56+
*/
57+
export interface PolymerDeepPropertyChange<B, V> {
58+
/** Path to the property that changed. */
59+
path: string;
60+
/** The object matching the non-wildcard portion of the path. */
61+
base: B;
62+
/** New value of the path that changed. */
63+
value: B|V;
64+
}
65+
66+
/**
67+
* A record of changes made to an array.
68+
* @template T The type of the array being observed.
69+
*/
70+
export interface PolymerSplice<T extends Array<{}|null|undefined>> {
71+
/** Position where the splice started. */
72+
index: number;
73+
/** Array of removed items. */
74+
removed: T;
75+
/** Number of new items inserted at index. */
76+
addedCount: number;
77+
/** A reference to the array in question. */
78+
object: T;
79+
/** The string literal 'splice'. */
80+
type: 'splice';
81+
}
82+
83+
/**
84+
* The object passed to ".splices" observers. A set of mutations made to the
85+
* array.
86+
* @template T The type of the array being observed.
87+
*/
88+
export interface PolymerSpliceChange<T extends Array<{}|null|undefined>> {
89+
indexSplices: Array<PolymerSplice<T>>;
90+
}
91+
5192
// Types from "externs/polymer-internal-shared-types.js"
5293

5394
export interface StampedTemplate extends DocumentFragment {

0 commit comments

Comments
 (0)