Skip to content

Commit

Permalink
Add TypeScript types for observer parameters. (#5359)
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
aomarks authored Sep 16, 2018
1 parent 4f11628 commit 912c19c
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions interfaces.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,47 @@ export type BehaviorInit = Pick<
Exclude<keyof PolymerInit, "is" | "extends" | "_template">
>;

/**
* The object passed to ".*" wildcard obsevers. A record of a change made to an
* object.
* @template B The object matching the non-wildcard portion of the path.
* @template V Additional types that could be set at the path.
*/
export interface PolymerDeepPropertyChange<B, V> {
/** Path to the property that changed. */
path: string;
/** The object matching the non-wildcard portion of the path. */
base: B;
/** New value of the path that changed. */
value: B|V;
}

/**
* A record of changes made to an array.
* @template T The type of the array being observed.
*/
export interface PolymerSplice<T extends Array<{}|null|undefined>> {
/** Position where the splice started. */
index: number;
/** Array of removed items. */
removed: T;
/** Number of new items inserted at index. */
addedCount: number;
/** A reference to the array in question. */
object: T;
/** The string literal 'splice'. */
type: 'splice';
}

/**
* The object passed to ".splices" observers. A set of mutations made to the
* array.
* @template T The type of the array being observed.
*/
export interface PolymerSpliceChange<T extends Array<{}|null|undefined>> {
indexSplices: Array<PolymerSplice<T>>;
}

// Types from "externs/polymer-internal-shared-types.js"

export interface StampedTemplate extends DocumentFragment {
Expand Down

0 comments on commit 912c19c

Please sign in to comment.