Skip to content

Redeclaration of Node_2 class causes type incompatibilty #1127

@hschletz

Description

@hschletz

I migrated my application to use the new dav module introduced in v3.10, but ran into a problem:

dist/dav.d.ts contains a redeclaration of the Node_2 class, which is a verbatim copy of the Node_2 class from the main module. Some functions, like resultToNode(), return an instance of the class from the dav module. This causes Problems with code that expects a Node or INode from the main module:

 error TS2345: Argument of type 'Node_2' is not assignable to parameter of type 'INode'.
  The types returned by 'clone()' are incompatible between these types.
    Type 'Node_2' is not assignable to type 'import("<project_path>/node_modules/@nextcloud/files/dist/index").Node'.
      Types have separate declarations of a private property '_data'.

As said, the declarations are 100% identical, but Typescript sees them as different types. There are some ugly workarounds:

  • Explicit cast: resultToNode() as unknown as INode (the intermediate cast to unknown is required to work around the perceived type incompatibility)
  • Change consuming code to allow a Node_2 from the dav module, but that looks more like an internal class name.

The redeclaration looks accidental to me. Should't there be only the Node_2 class from the main module?

Pseudocode to reproduce:

import { INode } from '@nextcloud/files'
import { resultToNode } from '@nextcloud/files/dav'

function test(node: INode) // same problem with Node
{
    return node
}

const node = resultToNode(...)
test(node) // results in above error

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions