From 912c19cc216970d0aabb605dfa7d7b9e4a3d1394 Mon Sep 17 00:00:00 2001 From: Alexander Marks Date: Sat, 15 Sep 2018 18:24:37 -0700 Subject: [PATCH] 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. --- interfaces.d.ts | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/interfaces.d.ts b/interfaces.d.ts index 79fb54cde4..61e0a2d37c 100644 --- a/interfaces.d.ts +++ b/interfaces.d.ts @@ -48,6 +48,47 @@ export type BehaviorInit = Pick< Exclude >; +/** + * 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 { + /** 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> { + /** 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> { + indexSplices: Array>; +} + // Types from "externs/polymer-internal-shared-types.js" export interface StampedTemplate extends DocumentFragment {