Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

191
Vistas
Why ASTPath<Function> is not assignable to parameter of type ASTPath<ASTNode>

I am using JSCodeshift to migrate some old JS files. One of the things I have to do is find all the functions (both normal and arrow functions) and then add some code to their body. To find both I just use the general Function constructor to search for all the possible functions. However, when I try to use the find nodes on the jscodeshift function I get a type error. So, this simple code can work as an example:

j(file.source).find(j.Function).filter((path) => {
  j(path) //  <- here is where the error happens
})

This is the full error:

Overload 2 of 2, '(source: ASTNode | ASTNode[] | ASTPath<ASTNode> | ASTPath<ASTNode>[]): Collection<any>', gave the following error.
    Argument of type 'ASTPath<Function>' is not assignable to parameter of type 'ASTNode | ASTNode[] | ASTPath<ASTNode> | ASTPath<ASTNode>[]'.
    Type 'NodePath<Function, Function>' is not assignable to type 'ASTPath<ASTNode>'.
    Type 'Function' is not assignable to type 'ASTNode'.
          Property 'key' is missing in type 'Function' but required in type 'ClassPrivateMethod'.ts(2769)

Looking at the definition of Error, it is extending ASTNode, so it should be compatible, no?

//ast-types/gen/namedTypes.d.ts
    interface Function extends Node {
        id?: K.IdentifierKind | null;
        params: K.PatternKind[];
        body: K.BlockStatementKind;
        generator?: boolean;
        async?: boolean;
        expression?: boolean;
        defaults?: (K.ExpressionKind | null)[];
        rest?: K.IdentifierKind | null;
        returnType?: K.TypeAnnotationKind | K.TSTypeAnnotationKind | null;
        typeParameters?: K.TypeParameterDeclarationKind | K.TSTypeParameterDeclarationKind | null;
        predicate?: K.FlowPredicateKind | null;
    }

However if I use ArrowFunctionExpression as find query:

j(file.source).find(j.ArrowFunctionExpression).filter((path) => {
  j(path)
})

it doesn't complain about the type, which is weird given that ArrowFunctionExpression just extends Function type

    interface ArrowFunctionExpression extends Omit<Function, "type" | "id" | "body" | "generator">, Omit<Expression, "type"> {
        type: "ArrowFunctionExpression";
        id?: null;
        body: K.BlockStatementKind | K.ExpressionKind;
        generator?: false;
    }
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda