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 improvement: Replace any with unknown where it makes sense #1087

Closed
lmammino opened this issue Aug 25, 2023 · 1 comment
Closed

Comments

@lmammino
Copy link
Member

As suggested by @bilalq in #1023:


As @m-radzikowski mentioned, the actual middleware typings could be improved. It'd be a breaking change, but types should use unknown instead of any. That would make them safe and force clients to validate their types match expectations without letting them unsafely access properties.

In the case of the secretsManager middleware, it would be even better for it to take an optional typeguard function. That would allow for exact type awareness without needing to resort to unknown or any. This would be useful even for non-TS consumers that are just using vanilla JS. If a secret value is fetched and it's shape doesn't match expectations, an error gets thrown, so the rest of the code can safely assume the secret shape is as expected.

As a general observation, I don't think there are issues with the general typing of middy itself, but there are improvements that could be made to the official middleware.

[...]

Originally posted by @bilalq in #1023 (comment)

@lmammino
Copy link
Member Author

We did this as part of the v5 branch. There might still be room for improvement, so feel free to re-open or submit new PRs if you think it's needed.

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

No branches or pull requests

1 participant