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

*ActivityOptions: make either timeout required #1523

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ikonst
Copy link
Contributor

@ikonst ikonst commented Sep 13, 2024

What was changed

*ActivityOptions types

Why?

We do this check in runtime:

function validateActivityOptions(options: ActivityOptions): void {
if (options.scheduleToCloseTimeout === undefined && options.startToCloseTimeout === undefined) {
throw new TypeError('Required either scheduleToCloseTimeout or startToCloseTimeout');
}
}

It can be easily expressed in TypeScript.

Checklist

  • How was this tested: Type checks pass

@ikonst ikonst requested a review from a team as a code owner September 13, 2024 14:44
@ikonst
Copy link
Contributor Author

ikonst commented Nov 13, 2024

@mjameswh can take a look?

@bergundy
Copy link
Member

FTR I considered defining the types this way initially but decided against it because it's harder to understand and doesn't render well in the generated documentation.

@ikonst
Copy link
Contributor Author

ikonst commented Nov 13, 2024

I can't trigger Build Docs, but trusting that's still the case we can close this PR.

@mjameswh
Copy link
Contributor

mjameswh commented Nov 14, 2024

FTR I considered defining the types this way initially but decided against it because it's harder to understand and doesn't render well in the generated documentation.

Yeah, that was my concern too, though I feel the build-time error would be highly desirable. Even I regularly make that error when writing samples/test code.

And yes, that's still a problem; we already have several such things in our doc, like this one:

Screenshot 2024-11-14 at 16 27 24

@mjameswh
Copy link
Contributor

Let's keep this PR open for now.

This "stricter type definition vs generated API docs readability" thing is already a problem, and will continue to grows over time. Both are important for DX. I would really want to look at how we can get the former without compromising too much on the latter.

One possibility might be to look at more readable ways to express the same type constraints. For example, in the specific case highlighted by @ikonst, a definition such as RequireEither<ActivityOptions, 'scheduleToCloseTimeout' | startToCloseTimeout> would probably result in more readable documentation.

Also, TypeDoc is actively working on various optimizations to how complex types get displayed in generated documentation. Some of these optimizations are automatic, but most must be turned on explicitly, e.g. by adding some doc annotation to the type. The
TypeDoc 0.27 Beta just introduced several new such optimizations. We should really explore these optimizations.

@Sushisource
Copy link
Member

My 2c is the build time error is way more important than marginally prettier docs. One of them stops you from making a mistake without you having to think, and the other is maybe slightly... distracting?

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.

4 participants