Skip to content

Improve some types from Deno #1759

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

Merged
merged 9 commits into from
Jul 28, 2024

Conversation

petamoriken
Copy link
Contributor

I am working on making the Deno types match the DOM types in this repository as closely as possible (denoland/deno#24599). I send a PR for the types that I think should be included in the TypeScript side.

Copy link
Contributor

Thanks for the PR!

This section of the codebase is owned by @saschanaz - if they write a comment saying "LGTM" then it will be merged.

Copy link
Contributor

@saschanaz saschanaz left a comment

Choose a reason for hiding this comment

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

Mostly looks good, thanks!

@@ -2573,7 +2573,7 @@
},
{
"name": "strategy",
"overrideType": "{ highWaterMark?: number }"
"overrideType": "{ highWaterMark?: number; size?: undefined }"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why an unused property? Who would be happy with this? Can you add a comment about that? (it's jsonc so it supports comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm okay, but doesn't TypeScript already show error for excessive fields?

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 a minor detail, but we can make new ReadableStream({ type: “bytes” }, { size: undefined }) be inferred as ReadableStream<Uint8Array>.

https://www.typescriptlang.org/play/?#code/MYewdgzgLgBATgRhgXhmApgdxgJXQQwBN8AjAG3QGUo4CBbACgG8YoBPAB3QC4YAiEmyjoIfGAF8ANDCbiAlACgA9EphqYAPQD8ChaEiw4AJhRosuAsXJUa9Zq049+g4aInSWEAJYAvJwFcwQnQAMy8MQglFFXVNHSA

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm that's interesting... Is that something frequently done by users?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In general, I believe that implementations that set properties to undefined are often used because it's easy to write, while spread syntax is required to implement empty properties in some cases.

const option1 = {
  foo: "foo",
  bar: setBar ? "bar" : undefined,
};

const option2 = {
  foo: "foo",
  ...(setBar ? { bar: "bar" } : {}),
};

Copy link
Contributor

Choose a reason for hiding this comment

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

But what is the hypothetical setBar here? readAsBytes? I would expect either always pass size or never pass size here than your conditional pass example, unless the caller also has the hypothetical setBar for type, which would be kinda complex setup to create ReadableStream. Especially when the way to read the resulting stream would be significantly different.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it is nonsense to consider whether or not to give ?: undefined per API; it is consistent to allow for the undefined assignment, as in TypeScript's Partial. However, if you have strong concerns here, I am not opposed to revert.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is nonsense to consider whether or not to give ?: undefined per API; it is consistent to allow for the undefined assignment, as in TypeScript's Partial. However, if you have strong concerns here, I am not opposed to revert.

Agreed that it's nonsense to decide per API (or at least hard to maintain), and I think it should not exist for consistency sake because it would be the first case if we add this here. That is unless we have a strong proof that there's many users who do setBar-style thing here (which I think doesn't make sense at least for this one).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it should not exist for consistency sake because it would be the first case if we add this here. That is unless we have a strong proof that there's many users who do setBar-style thing here (which I think doesn't make sense at least for this one).

Agreed. I reverted this change.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks, I'll see whether #1713 is ready enough to be merged and when I can land this.

@saschanaz
Copy link
Contributor

#1713 should probably just rebuild if merge conflict happens, so I'll just proceed here. LGTM, thanks!

@github-actions github-actions bot merged commit 3ac538d into microsoft:main Jul 28, 2024
5 of 7 checks passed
Copy link
Contributor

Merging because @saschanaz is a code-owner of all the changes - thanks!

@petamoriken petamoriken deleted the feat/improve-types branch July 29, 2024 02:11
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