refactor: utilize type narrowing (#33075)

PR Close #33075
This commit is contained in:
Danny Skoog
2019-10-09 17:17:52 +02:00
committed by Miško Hevery
parent 1ae77da609
commit 6ab5f3648a
29 changed files with 73 additions and 80 deletions

View File

@ -81,7 +81,7 @@ export function isNodeMatchingSelector(
const current = selector[i];
if (typeof current === 'number') {
// If we finish processing a :not selector and it hasn't failed, return false
if (!skipToNextSelector && !isPositive(mode) && !isPositive(current as number)) {
if (!skipToNextSelector && !isPositive(mode) && !isPositive(current)) {
return false;
}
// If we are skipping to the next :not() and this mode flag is positive,

View File

@ -195,7 +195,7 @@ class TQuery_ implements TQuery {
private matchTNode(tView: TView, tNode: TNode): void {
if (Array.isArray(this.metadata.predicate)) {
const localNames = this.metadata.predicate as string[];
const localNames = this.metadata.predicate;
for (let i = 0; i < localNames.length; i++) {
this.matchTNodeWithReadOption(tView, tNode, getIdxOfMatchingSelector(tNode, localNames[i]));
}

View File

@ -73,9 +73,8 @@ export function setUpAttributes(renderer: Renderer3, native: RElement, attrs: TA
}
} else {
isProc ?
(renderer as ProceduralRenderer3)
.setAttribute(native, attrName as string, attrVal as string) :
native.setAttribute(attrName as string, attrVal as string);
(renderer as ProceduralRenderer3).setAttribute(native, attrName, attrVal as string) :
native.setAttribute(attrName, attrVal as string);
}
i++;
}

View File

@ -424,7 +424,7 @@ export function normalizeIntoStylingMap(
if (props) {
for (let i = 0; i < props.length; i++) {
const prop = props[i] as string;
const prop = props[i];
const newProp = normalizeProps ? hyphenate(prop) : prop;
const value = allValuesTrue ? true : map ![prop];
addItemToStylingMap(stylingMapArr, newProp, value, true);

View File

@ -88,9 +88,8 @@ class SafeResourceUrlImpl extends SafeValueImpl implements SafeResourceUrl {
}
export function unwrapSafeValue(value: string | SafeValue): string {
return value instanceof SafeValueImpl ?
(value as SafeValueImpl).changingThisBreaksApplicationSecurity :
(value as string);
return value instanceof SafeValueImpl ? value.changingThisBreaksApplicationSecurity :
value as string;
}
@ -116,8 +115,7 @@ export function allowSanitizationBypassAndThrow(value: any, type: BypassType): b
}
export function getSanitizationBypassType(value: any): BypassType|null {
return value instanceof SafeValueImpl && (value as SafeValueImpl).getTypeName() as BypassType ||
null;
return value instanceof SafeValueImpl && value.getTypeName() as BypassType || null;
}
/**

View File

@ -45,7 +45,7 @@ export function asyncFallback(fn: Function): (done: any) => any {
}
runInTestZone(fn, this, done, (err: any) => {
if (typeof err === 'string') {
return done.fail(new Error(<string>err));
return done.fail(new Error(err));
} else {
done.fail(err);
}