1

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[])]> {



    }
}
JGFMK
  • 8,425
  • 4
  • 58
  • 92
  • -- i got down vote but i have no idea why? `For example the '?' type safe navigator I found out about is an Angular embellishment to Typescript` - it's not there in typescript or angular. – Daniel Tran Jul 20 '17 at 08:28
  • 1
    1) https://angular.io/guide/template-syntax and 2) https://angular.io/guide/template-syntax#expression-operators 3) https://angular.io/guide/template-syntax#the-safe-navigation-operator----and-null-property-paths – JGFMK Jul 20 '17 at 10:34
  • 1
    It's in angular template code only, not in typescript. – Daniel Tran Jul 20 '17 at 10:38
  • Ok.. get your point Template syntax - vs... Typescript.. Will cross out that part. – JGFMK Jul 20 '17 at 10:40

1 Answers1

-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.
Daniel Tran
  • 6,083
  • 12
  • 25
  • 1
    I suspect you got a down-vote, because, if you had followed the links for point 3 you would see that was an incorrect statement. From what I can tell () is a necessity for the Tuple definition as defined in the Resolve signature. – JGFMK Jul 20 '17 at 08:38