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

Fix TypeScript Error in isConstructor #412

Merged
merged 3 commits into from
Jan 26, 2025

Conversation

SanderMuller
Copy link
Contributor

This PR resolves a TypeScript error in the isConstructor utility function and improves error handling for enhanced type safety.

Key Changes

  1. TypeScript Error Fix:

    • Resolved the TS18046: 'err' is of type 'unknown' error by explicitly checking whether the caught err is an instance of Error before accessing its message.
  2. Improved Error Handling:

    • Updated the catch block to specifically handle cases where obj is not a valid constructor by checking the error message for "is not a constructor."
  3. unknown instead of any

    • Using unknown instead of any aligns with TypeScript best practices by forcing developers to explicitly assert or narrow types, reducing potential runtime errors.

TS error TS18046 only happens when running TS in strict, so in the Echo project itself you don't see it until enabling strict, but our TS config falls over this library implementation, and the change is a net benefit IMO.

node_modules/laravel-echo/src/util/index.ts:5:13 - error TS18046: 'err' is of type 'unknown'.
@taylorotwell taylorotwell merged commit 85f7c11 into laravel:master Jan 26, 2025
6 checks passed
@SanderMuller SanderMuller deleted the fix-ts-error branch January 27, 2025 21:45
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

Successfully merging this pull request may close these issues.

None yet

2 participants