Philipp Schrader | 3d7dedc | 2024-03-16 16:27:25 -0700 | [diff] [blame] | 1 | import {Pipe, PipeTransform} from '@angular/core'; |
2 | |||||
3 | @Pipe({name: 'cast'}) | ||||
4 | export class CastPipe implements PipeTransform { | ||||
5 | /** | ||||
6 | * Cast (S: SuperType) into (T: Type) using @Generics. | ||||
7 | * @param value (S: SuperType) obtained from input type. | ||||
8 | * @optional @param type (T CastingType) | ||||
9 | * type?: { new (): T } | ||||
10 | * type?: new () => T | ||||
11 | */ | ||||
12 | transform<S, T extends S>(value: S, type?: new () => T): T { | ||||
13 | return <T>value; | ||||
14 | } | ||||
15 | } |