Property 'transform' is not assignable to the same property in base type

Viewed 166

In Angular version 4, it has a built-in DecimalPipe, which has a method transform with two parameters

In my project, it is extended :

@Pipe({ name: 'numberx' })
export class NumberxPipe extends DecimalPipe {
  transform(value: string, format: string = null, convertSuffix: boolean = true): string {
    if(convertSuffix){
        ...
    } else {
      return super.transform(value, format);
    }
  }

AS you can see, I added third parameter and it works well.

Now I upgraded my project to Angular 6 and found an issue around it: transform method in DecimalPipe now has three parameters:

 transform(value: any, digitsInfo?: string, locale?: string): string | null;

Now my code can't be compiled because it complains:

Property 'transform' in type 'NumberxPipe' is not assignable to the same property in base type

I have to rename my transform to transform2 to avoid this compiling error. But the caller will find two methods, which is not what I want.

I saw somebody discussed a similar issue in Overwrite/override method signature in TypeScript interface

But mine is not related to return type.

I also knew The override keyword is now implemented since version 4.3 in Typescript, But mine is 2.9.2.

0 Answers
Related