fix(common): correct typing and implementation of SlicePipe (#37447)
Even in the overloads, state that it can accept `null` and `undefined`, in order to ensure easy composition with `async`. Additionally, change the implementation to return `null` on an `undefined` input, for consistency with other pipes. BREAKING CHANGE: The `slice` pipe now returns `null` for the `undefined` input value, which is consistent with the behavior of most pipes. If you rely on `undefined` being the result in that case, you now need to check for it explicitly. PR Close #37447
This commit is contained in:
committed by
Alex Rickabaugh
parent
4dfe0fa068
commit
4744c229db
@@ -62,11 +62,13 @@ export class SlicePipe implements PipeTransform {
|
||||
* - **if negative**: return all items before `end` index from the end of the list or string.
|
||||
*/
|
||||
transform<T>(value: ReadonlyArray<T>, start: number, end?: number): Array<T>;
|
||||
transform(value: null|undefined, start: number, end?: number): null;
|
||||
transform<T>(value: ReadonlyArray<T>|null|undefined, start: number, end?: number): Array<T>|null;
|
||||
transform(value: string, start: number, end?: number): string;
|
||||
transform(value: null, start: number, end?: number): null;
|
||||
transform(value: undefined, start: number, end?: number): undefined;
|
||||
transform(value: any, start: number, end?: number): any {
|
||||
if (value == null) return value;
|
||||
transform(value: string|null|undefined, start: number, end?: number): string|null;
|
||||
transform<T>(value: ReadonlyArray<T>|string|null|undefined, start: number, end?: number):
|
||||
Array<T>|string|null {
|
||||
if (value == null) return null;
|
||||
|
||||
if (!this.supports(value)) {
|
||||
throw invalidPipeArgumentError(SlicePipe, value);
|
||||
|
||||
Reference in New Issue
Block a user