Skip to content

Suggestions for modifications to PipeTransform examples #42239

@RudyBlack

Description

@RudyBlack

Description

As you can see on the reference below, the case "truncate" only for strings.

import {Pipe, PipeTransform} from '@angular/core';

@Pipe({name: 'truncate'})
export class TruncatePipe implements PipeTransform {
  transform(value: any) {
    return value.split(' ').slice(0, 2).join(' ') + '...';
  }
}

(in this example, return value.split(' ')slice(0, 2).join(' ') + '…' in .split is a string-only built-in object method.)

The parameter type value of the 'transform' method is any, but at least in the example truncate, the parameter of 'transform' must be string.

Therefore, it seems that it should be changed to 'transform(value: string)' or that there should be a logic inside to check if the type value is string.

Minimal Reproduction

What's the affected URL?**

https://angular.io/api/core/PipeTransform#usage-notes

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions