Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript File Type Shadowing in GetFile() Function #6

Open
OlufNielsen opened this issue Jan 3, 2025 · 1 comment
Open

TypeScript File Type Shadowing in GetFile() Function #6

OlufNielsen opened this issue Jan 3, 2025 · 1 comment

Comments

@OlufNielsen
Copy link

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
@ITHitBuild
Copy link
Contributor

As far as I see this is an issue with class reference documentation. We are working to resolve it in the next update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants