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

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

问题描述

在这段代码中,有人可以解释为什么/何时需要,我认为在 Typescript 中被称为表达式包装的经验法则?即 <[Parent, (Children[])]>.

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. 例如,如果我定义了一个元组类型并在主代码的解析工具/方法签名中使用它,您是否还需要将 '(' ')' 包裹在 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 if ((a > b) && (c
  3. Angular2(打字稿)使用打字稿.<代码>'?'类型安全导航器 不适用于角度或打字稿.打字稿中的所有内容都将在 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天全站免登陆