fix(platform-browser): debug element query predicates not compatible with strictFunctionTypes (#30993)

Currently developers can use the `By` class to construct common
`DebugElement` query predicates. e.g. `By.directive(MyDirective)`.

The `directive()` and `all()` predicates are currently returning
a predicate that works for `DebugElement` nodes. This return type
is too strict since the predicate is not specific to `DebugElement`
instances and can also apply to `DebugNode` instances.

Meaning that developers are currently able to use the `directive()`
predicate when using `queryAllNodes()`. This is a common practice
but will break when the project is compiled with TypeScript's
`--strictFunctionTypes` flag as the `DebugElement` predicate type
is not assignable to predicates for `DebugNode`. In order to make
these predicates usable with `--strictFuntionTypes` enabled, we
adjust the predicate type to reflect what is actually needed for
evaluation of the predicate.

PR Close #30993
This commit is contained in:
Paul Gschwendtner
2019-06-14 13:12:34 +02:00
committed by Miško Hevery
parent 647d7bdd88
commit 10a1e1974b
2 changed files with 8 additions and 8 deletions

View File

@ -9,9 +9,9 @@ export declare class BrowserTransferStateModule {
}
export declare class By {
static all(): Predicate<DebugElement>;
static all(): Predicate<DebugNode>;
static css(selector: string): Predicate<DebugElement>;
static directive(type: Type<any>): Predicate<DebugElement>;
static directive(type: Type<any>): Predicate<DebugNode>;
}
export declare function disableDebugTools(): void;