How do I fix the TypeScript error: TS2234: All declarations of an interface must have identical type parameters

StackOverflow https://stackoverflow.com/questions/23307510

  •  09-07-2023
  •  | 
  •  

Pregunta

In typescript v0.9.5 this code compiled.

interface Array {
    indexOfField : (propertyName: string, value: any) => number;
 }

After upgrading to typescript 1.0, I get the following error:

(2,11): error TS2234: All declarations of an interface must have identical type parameters.

Line number 2:11 is the keyword Array.

How do I fix this?

¿Fue útil?

Solución

The other definition of Array is Array<T> (with a type parameter) in lib.d.ts. You need to declare yours as:

interface Array<T> {
    indexOfField : (propertyName: string, value: any) => number;
}

in order to have the same number of type parameters.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top