Expression wrapping in Angular/Typescript: Need explanation of Rule of thumb for when/where it's required

℡╲_俬逩灬. 提交于 2019-12-23 01:37:20

问题


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.


来源:https://stackoverflow.com/questions/45177003/expression-wrapping-in-angular-typescript-need-explanation-of-rule-of-thumb-for

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!