Expression wrapping in Angular/Typescript: Need ex

2019-06-08 10:06发布

问题:

In this code, can someone explain the rule of thumb for, why/when there is a need for, what I believe is called, expression wrapping within Typescript? i.e. the '(' ')' in <[Parent, (Children[])]>.

  1. If I defined a tuple type for example and used that in the resolve implements/method signature of the main code, would you still need the '(' ')' wrapped around the array of Children?

  2. Are there other scenarios in Typescript/Angular where 'expression wrapping' occurs too?

  3. Is the specific to Angular? For example the '?' type safe navigator I found out about is an Angular embellishment to Typescript, not yet part of the language. See here and here and here.

type parentChildTuple = [Parent, Children[] ]

- versus

type parentChildTuple = [Parent, (Children[]) ] 

import { Injectable } from '@angular/core';
import { Resolve, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Observable } from 'rxjs';

@Injectable()
export class DataComponentResolver implements Resolve<[Parent, (Children[])]> {

    constructor() {

    }

    resolve(
        route: ActivatedRouteSnapshot,
        state: RouterStateSnapshot): Observable<[Parent, (Children[])]> {



    }
}

回答1:

  1. What you say about expression wrapping is just for making the code clearer. Not have any effect.
  2. It's the same when you say: if (a > b && c < d) -> if ((a > b) && (c < d))
  3. Angular2 (typescript) uses typescript. '?' type safe navigator is not there for angular nor typescript. Everything in typescript will be there in Angular and vice versa.