Angular/Typescript中的表达式换行:需要何时/何处需要经验法则的解释 [英] Expression wrapping in Angular/Typescript: Need explanation of Rule of thumb for when/where it's required

查看:92
本文介绍了Angular/Typescript中的表达式换行:需要何时/何处需要经验法则的解释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这段代码中,有人可以解释一下为什么要在Typescript中使用表达式包装吗?为什么/何时需要? 即< [父母,(孩子[]]]> 中的'('')'.

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. 例如,如果我定义一个元组类型并将其用于主代码的resolve实现/方法签名中,您是否还需要将'('')'包裹在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?

在Typescript/Angular中是否还有其他发生"表达式换行"的情况?

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


type parentChildTuple = [Parent, Children[] ]

-与

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. 您对表达式包装所说的只是为了使代码更清晰.没有任何效果.
  2. 您说的是相同的:if(a> b& c< d)-> if((a> b)&&(c< d))
  3. Angular2(打字稿)使用打字稿. '?' type safe navigator既不存在角度字符也不存在打字稿.打字稿中的所有内容都将出现在Angular中,反之亦然.
  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.

这篇关于Angular/Typescript中的表达式换行:需要何时/何处需要经验法则的解释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆