Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TypeScript types for observer parameters. #5359

Merged
merged 5 commits into from
Sep 16, 2018
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions interfaces.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,47 @@ export interface PolymerInit {
listeners?: {[key: string]: string};
}

/**
* 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;
rictic marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* A record of changes made to an array.
* @template T The type of the array being observed.
*/
export interface PolymerSplice<T extends Array<{}>> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer unknown over {} as {} is non-nullable. T extends Array<unknown>

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unknown isn't in g3 yet, how about {}|null|undefined for now? I think any is actually safe here too, because I think in this context (constraining by supertype), the any wouldn't leak anywhere (but I would avoid it just so linters don't complain)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{}|null|undefined is good.

You're right about any, I'd just like to avoid using it as much as possible.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

/** 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<{}>> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer unknown

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See other thread.

indexSplices: Array<PolymerSplice<T>>;
}

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

export interface StampedTemplate extends DocumentFragment {
Expand Down