I'm currently working on reusing an existing currency pipe from Angular common. My objective is to truncate the .00 when the value is round. Here's the code I've come up with:
/** Transform currency string and round it. */
@Pipe({name: 'customCurrency'})
export class CustomCurrencyPipe extends CurrencyPipe implements PipeTransform {
transform(value: number|string|null|undefined): string|null {
if (!isValue(value)) return null;
const valueFormat = (+value % 1 === 0) ? '1.0-0' : '1.2-2';
return super.transform(value, 'USD', 'symbol', valueFormat);
}
}
function isValue(value: number|string|null|undefined): value is number|string {
return !(value == null || value === '' || value !== value);
}
If I set the transform type to :any, it runs without any issues. However, I am restricted from using any in the current environment. Setting it to :string|null results in this error:
TS2416: Property 'transform' in type 'CustomCurrencyPipe' is not assignable to the same property in base type 'CurrencyPipe'.
Type '(value: string | number | null | undefined) => string | null' is not assignable to type '{ (value: string | number, currencyCode?: string | undefined, display?: string | boolean | undefined, digitsInfo?: string | undefined, locale?: string | undefined): string | null; (value: null | undefined, currencyCode?: string | undefined, display?: string | ... 1 more ... | undefined, digitsInfo?: string | undefin...'.
Type 'string | null' is not assignable to type 'null'.
Type 'string' is not assignable to type 'null'.
7 transform(value: number|string|null|undefined): string|null {
Is there a way for me to set my return type so that it matches the signature of the extended pipe?