'TypeScript Promise return type issue

I am having a recursive function traverseSchemas, which traverse through nested JSONschema and parse them (loadSchema an async function) and return some data structure.

Here I am trying to return the data => [{object}, [object]] .

const traverseSchemas =  async (
      filepath:string,
      isRoot: boolean
    ) => 
      {
      const refSchemaData = await loadSchema(
        filepath,
        isRoot
      )
      const refSchemas = generatePaths(refSchemaData, "$ref");
      const ref_ = _.filter(refSchemas, (o) => {
          if (o.values.includes(".json")) return o;
      });
      const schemaObj: Record<string, any> = {};
      schemaObj[_.get(refSchemaData, "$id")] = refSchemaData;
      
      const data = await Promise.all(_.map(ref_,  async (o) => {
            return await traverseSchemas(_.get(o, "values"), false)
        }).flat()).then((values) => {
          return [schemaObj].concat(values)
        })
  
      return data
    };

But I am getting below 2 errors

'traverseSchemas' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.

'data' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

console.log(data) gives me desired output . I am guessing something very basic of Promise I am missing here.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source