diff --git a/types/selenium-webdriver/index.d.ts b/types/selenium-webdriver/index.d.ts index 449f79c678..4e8ce55986 100644 --- a/types/selenium-webdriver/index.d.ts +++ b/types/selenium-webdriver/index.d.ts @@ -862,49 +862,8 @@ export namespace promise { * @interface * @template T */ - class Thenable implements IThenable { - /** - * Registers listeners for when this instance is resolved. - * - * @param onfulfilled - * The function to call if this promise is successfully resolved. The function - * should expect a single argument: the promise's resolved value. - * @param onrejected - * The function to call if this promise is rejected. The function should - * expect a single argument: the rejection reason. - * @return A new promise which will be resolved with the result - * of the invoked callback. - * @template R - */ - then( - onfulfilled?: ((value: T) => TResult1 | PromiseLike) | undefined | null, - onrejected?: ((reason: any) => TResult2 | PromiseLike) | undefined | null): Promise; - - /** - * Registers a listener for when this promise is rejected. This is synonymous - * with the {@code catch} clause in a synchronous API: - * - * // Synchronous API: - * try { - * doSynchronousWork(); - * } catch (ex) { - * console.error(ex); - * } - * - * // Asynchronous promise API: - * doAsynchronousWork().catch(function(ex) { - * console.error(ex); - * }); - * - * @param {function(*): (R|IThenable)} errback The - * function to call if this promise is rejected. The function should - * expect a single argument: the rejection reason. - * @return {!ManagedPromise} A new promise which will be - * resolved with the result of the invoked callback. - * @template R - */ - catch(errback: Function): Promise; - + interface Thenable extends IThenable {} + class Thenable { /** * Registers a listener to invoke when this promise is resolved, regardless * of whether the promise's value was successfully computed. This function @@ -2025,7 +1984,8 @@ export class Alert { * @implements {promise.Thenable.} * @final */ -export class AlertPromise extends Alert implements promise.IThenable { +export interface AlertPromise extends promise.IThenable {} +export class AlertPromise extends Alert { /** * @param {!WebDriver} driver The driver controlling the browser this * alert is attached to. @@ -2033,48 +1993,6 @@ export class AlertPromise extends Alert implements promise.IThenable { * that will be fulfilled with the promised alert. */ constructor(driver: WebDriver, alert: promise.Promise); - - // region Methods - - /** - * Registers listeners for when this instance is resolved. This function most - * overridden by subtypes. - * - * @param opt_callback The function to call if this promise is - * successfully resolved. The function should expect a single argument: the - * promise's resolved value. - * @param opt_errback The function to call if this promise is - * rejected. The function should expect a single argument: the rejection - * reason. - * @return A new promise which will be resolved - * with the result of the invoked callback. - */ - then(opt_callback?: Function, opt_errback?: Function): promise.Promise; - - /** - * Registers a listener for when this promise is rejected. This is synonymous - * with the {@code catch} clause in a synchronous API: - * - * // Synchronous API: - * try { - * doSynchronousWork(); - * } catch (ex) { - * console.error(ex); - * } - * - * // Asynchronous promise API: - * doAsynchronousWork().catch(function(ex) { - * console.error(ex); - * }); - * - * @param {function(*): (R|IThenable)} errback The - * function to call if this promise is rejected. The function should - * expect a single argument: the rejection reason. - * @return {!ManagedPromise} A new promise which will be - * resolved with the result of the invoked callback. - * @template R - */ - catch(errback: Function): promise.Promise; } /** @@ -4776,7 +4694,8 @@ export class WebElement implements Serializable { * @implements {promise.Thenable.} * @final */ -export class WebElementPromise extends WebElement implements promise.IThenable { +export interface WebElementPromise extends promise.IThenable {} +export class WebElementPromise extends WebElement { /** * @param {!WebDriver} driver The parent WebDriver instance for this * element. @@ -4784,59 +4703,6 @@ export class WebElementPromise extends WebElement implements promise.IThenable); - - /** - * Registers listeners for when this instance is resolved. - * - * @param opt_callback The - * function to call if this promise is successfully resolved. The function - * should expect a single argument: the promise's resolved value. - * @param opt_errback The - * function to call if this promise is rejected. The function should expect - * a single argument: the rejection reason. - * @return A new promise which will be - * resolved with the result of the invoked callback. - */ - then(opt_callback?: (value: WebElement) => promise.Promise, opt_errback?: (error: any) => any): promise.Promise; - - /** - * Registers listeners for when this instance is resolved. - * - * @param opt_callback The - * function to call if this promise is successfully resolved. The function - * should expect a single argument: the promise's resolved value. - * @param opt_errback The - * function to call if this promise is rejected. The function should expect - * a single argument: the rejection reason. - * @return A new promise which will be - * resolved with the result of the invoked callback. - */ - then(opt_callback?: (value: WebElement) => R, opt_errback?: (error: any) => any): promise.Promise; - - /** - * Registers a listener for when this promise is rejected. This is synonymous - * with the {@code catch} clause in a synchronous API: - * - * // Synchronous API: - * try { - * doSynchronousWork(); - * } catch (ex) { - * console.error(ex); - * } - * - * // Asynchronous promise API: - * doAsynchronousWork().catch(function(ex) { - * console.error(ex); - * }); - * - * @param {function(*): (R|IThenable)} errback The - * function to call if this promise is rejected. The function should - * expect a single argument: the rejection reason. - * @return {!ManagedPromise} A new promise which will be - * resolved with the result of the invoked callback. - * @template R - */ - catch(errback: Function): promise.Promise; } /** diff --git a/types/selenium-webdriver/test/index.ts b/types/selenium-webdriver/test/index.ts index 56e0ad0cb2..2dd80918ae 100644 --- a/types/selenium-webdriver/test/index.ts +++ b/types/selenium-webdriver/test/index.ts @@ -30,6 +30,8 @@ function TestBuilder() { builder = builder.withCapabilities({ something: true }); } +declare const promise: webdriver.promise.Promise; + function TestActionSequence() { let driver: webdriver.WebDriver = new webdriver.Builder(). withCapabilities(webdriver.Capabilities.chrome()). @@ -37,7 +39,6 @@ function TestActionSequence() { let sequence: webdriver.ActionSequence = new webdriver.ActionSequence(driver); let element: webdriver.WebElement = new webdriver.WebElement(driver, 'elementId'); - let promise: webdriver.promise.Promise; element = new webdriver.WebElement(driver, promise); // Click @@ -519,7 +520,7 @@ function TestWebDriverOptions() { promise = options.deleteAllCookies(); promise = options.deleteCookie('name'); options.getCookie('name').then((cookie: webdriver.IWebDriverCookie) => { - let expiry: number = cookie.expiry; + let expiry: number | undefined = cookie.expiry; }); options.getCookies().then((cookies: webdriver.IWebDriverCookie[]) => { }); @@ -573,9 +574,13 @@ function TestWebDriverWindow() { voidPromise = window.setSize(12, 34); } +declare const sessionPromise: webdriver.promise.Promise; +declare let booleanPromise: webdriver.promise.Promise; +declare const booleanCondition: webdriver.Condition; +declare const webElementCondition: webdriver.WebElementCondition; + function TestWebDriver() { let session: webdriver.Session = new webdriver.Session('ABC', webdriver.Capabilities.android()); - let sessionPromise: webdriver.promise.Promise; let httpClient: http.HttpClient = new http.HttpClient('http://someserver'); let executor: http.Executor = new http.Executor(httpClient); let flow: webdriver.promise.ControlFlow = new webdriver.promise.ControlFlow(); @@ -586,7 +591,6 @@ function TestWebDriver() { let voidPromise: webdriver.promise.Promise; let stringPromise: webdriver.promise.Promise; - let booleanPromise: webdriver.promise.Promise; let webElementPromise: webdriver.WebElementPromise; let actions: webdriver.ActionSequence = driver.actions(); @@ -643,7 +647,6 @@ function TestWebDriver() { voidPromise = driver.sleep(123); stringPromise = driver.takeScreenshot(); - let booleanCondition: webdriver.Condition; booleanPromise = driver.wait(booleanPromise); booleanPromise = driver.wait(booleanCondition); booleanPromise = driver.wait((driver: webdriver.WebDriver) => true); @@ -651,7 +654,6 @@ function TestWebDriver() { booleanPromise = driver.wait((driver: webdriver.WebDriver) => webdriver.promise.Promise.resolve(true)); booleanPromise = driver.wait(booleanPromise, 123); booleanPromise = driver.wait(booleanPromise, 123, 'Message'); - let webElementCondition: webdriver.WebElementCondition; webElementPromise = driver.wait(webElementCondition); voidPromise = driver.wait(webElementCondition).click(); @@ -659,8 +661,9 @@ function TestWebDriver() { driver = webdriver.WebDriver.createSession(executor, webdriver.Capabilities.android()); } +declare const serializable: webdriver.Serializable; + function TestSerializable() { - let serializable: webdriver.Serializable; let serial: string | webdriver.promise.IThenable = serializable.serialize(); } @@ -669,7 +672,6 @@ function TestWebElement() { withCapabilities(webdriver.Capabilities.chrome()). build(); - let promise: webdriver.promise.Promise; let element: webdriver.WebElement; element = new webdriver.WebElement(driver, 'elementId'); @@ -764,13 +766,14 @@ function TestLoggingEntry() { let type: string = entry.type; } +declare let stringPromise: webdriver.promise.Promise; + function TestPromiseModule() { let cancellationError: webdriver.promise.CancellationError = new webdriver.promise.CancellationError(); cancellationError = new webdriver.promise.CancellationError('message'); let str: string = cancellationError.message; str = cancellationError.name; - let stringPromise: webdriver.promise.Promise; let numberPromise: webdriver.promise.Promise; let booleanPromise: webdriver.promise.Promise; let voidPromise: webdriver.promise.Promise; @@ -932,8 +935,9 @@ function TestDeferred() { deferred.removeAll(); } +declare const controlFlow: webdriver.promise.ControlFlow; + function TestPromiseClass() { - let controlFlow: webdriver.promise.ControlFlow; let promise: webdriver.promise.Promise; promise = new webdriver.promise.Promise((resolve, reject) => { resolve(""); diff --git a/types/selenium-webdriver/tsconfig.json b/types/selenium-webdriver/tsconfig.json index 7d73075252..d76ee77a23 100644 --- a/types/selenium-webdriver/tsconfig.json +++ b/types/selenium-webdriver/tsconfig.json @@ -7,7 +7,7 @@ ], "noImplicitAny": true, "noImplicitThis": false, - "strictNullChecks": false, + "strictNullChecks": true, "baseUrl": "../", "typeRoots": [ "../" diff --git a/types/selenium-webdriver/tslint.json b/types/selenium-webdriver/tslint.json index 1a4b62ea03..5ffc468766 100644 --- a/types/selenium-webdriver/tslint.json +++ b/types/selenium-webdriver/tslint.json @@ -9,6 +9,8 @@ "jsdoc-format": false, "no-empty-interface": false, "no-inferrable-types": false, + "no-any-union": false, + "no-unnecessary-generics": false, "prefer-const": false, "semicolon": false, "unified-signatures": false