Skip to content

TypeScript File Type Shadowing in GetFile() Function #6

@OlufNielsen

Description

@OlufNielsen

Description

The GetFile() function in the codebase references the File type. However, due to the presence of the ITHit.WebDAV.Client.File type in the ITHit WebDAV client library, TypeScript resolves File to the library's type instead of the global File type provided by the browser.

In my codebase, I am receiving objects of the global File type (e.g., from file uploads or other browser APIs). However, the library-defined File type causes TypeScript to infer incorrectly, leading to type mismatches and confusion.

Steps to Reproduce

  1. Inspect the GetFile() function located on line 3216 of the codebase.
  2. Note that File resolves to ITHit.WebDAV.Client.File instead of the browser's global File type.

Expected Behavior

The GetFile() function should reference the global File type provided by the browser, ensuring compatibility with browser APIs and consistent type inference.

Actual Behavior

TypeScript resolves File to ITHit.WebDAV.Client.File, shadowing the global type. This results in incorrect type inference when handling browser File objects in my project.

Suggested Fix

Update the GetFile() function's return type in the index.d.ts file to explicitly reference the global File type and handle cases where no file is returned. For example:

 GetFile(): globalThis.File | null; 

This change ensures that any reference to File in the library correctly points to the global File type. It prevents downstream consumers from experiencing type shadowing or conflicts.

Additional Context

  • The global File type is a key part of my codebase, as it is used to handle files from user inputs (e.g., <input type="file">) and other browser APIs.
  • The shadowing issue has caused confusion and type mismatches, requiring workarounds that could be avoided with the proposed fix.

Environment

  • TypeScript Version: 5.5.3
  • Library: ITHit WebDAV Client v5.21.6001.0

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