Skip to content

Instantly share code, notes, and snippets.

@rctay
Created December 19, 2018 01:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rctay/df8c2190993ca976a31e7ec49c9a1389 to your computer and use it in GitHub Desktop.
Save rctay/df8c2190993ca976a31e7ec49c9a1389 to your computer and use it in GitHub Desktop.
Explicit typing for merging 2 objects/decorating in TypeScript with intersection types
import { $ } from 'protractor';
export interface ChangePasswordDialog {
currentPasswordField: ElementFinder;
incorrectPasswordError: ElementFinder;
submitButton: ElementFinder;
}
export class SettingsPage extends AppPage {
get changePasswordDialog(): ElementFinder & ChangePasswordDialog {
const func: ElementFinder = $('app-reset-password-dialog');
const addOns: ChangePasswordDialog = {
get currentPasswordField() { return func.$('input[name="currentPassword"]'); },
get incorrectPasswordError() { return func.$('.reset_password__incorrect-password'); },
get submitButton() { return func.$('.password-dialog__confirm-button'); },
};
return Object.assign(func, addOns);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment