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

chore(server): easy js to ts migrations #2 - objectStorage.ts #3396

Merged
merged 2 commits into from
Oct 25, 2024

Conversation

fabis94
Copy link
Contributor

@fabis94 fabis94 commented Oct 25, 2024

Description & motivation

Changes:

To-do before merge:

Screenshots:

Validation of changes:

Checklist:

  • My pull request follows the guidelines in the Contributing guide?
  • My pull request does not duplicate any other open Pull Requests for the same update/change?
  • My commits are related to the pull request and do not amend unrelated code or documentation.
  • My code follows a similar style to existing code.
  • I have added appropriate tests.
  • I have updated or added relevant documentation.

References

} catch (err) {
if (err instanceof S3ServiceException && err.Code === 'NoSuchKey')
if (err instanceof S3ServiceException && get(err, 'Code') === 'NoSuchKey')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get(err, Code)

no such prop according to TS, hence the dynamic access

@@ -51,32 +61,45 @@ const getObjectStorage = () => ({
createBucket: createS3Bucket()
})

const sendCommand = async (command) => {
const sendCommand = async <CommandOutput>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, nice use of generics. I think this is where I got stuck!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice that when sendCommand is called we don't specify what CommandOutput is. Is it inferred from the usage?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

return await client.send(command(Bucket))
const ret = (await client.send(
command(Bucket) as Command<any, any, any, any, any>
)) as CommandOutput
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of as CommandOutput. Is there a safer way of doing this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's already as CommandOutput in practice, the type of CommandOutput is auto inferred from the actual command you pass in. The only reason I need to do this is because of all of the abstraction and generics behind the scene which break something - I dunno, it wasn't obvious to me how to avoid it.

iainsproat
iainsproat previously approved these changes Oct 25, 2024
@fabis94 fabis94 requested a review from iainsproat October 25, 2024 10:37
@fabis94 fabis94 merged commit 64c3a5c into main Oct 25, 2024
23 of 25 checks passed
@fabis94 fabis94 deleted the fabians/quick-js-to-ts-2 branch October 25, 2024 11:00
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.

2 participants