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

[SDK-1640] Remove the Types namespace #1518

Merged
merged 6 commits into from
Jan 9, 2024

Conversation

lawrence-forooghian
Copy link
Collaborator

@lawrence-forooghian lawrence-forooghian commented Nov 30, 2023

We’re removing it because we believe that it’s more consistent with other JS libraries for users to write import * as Ably from 'ably' and then access types on the Ably namespace.

See commit messages for more details. In particular, I'd welcome feedback on the rename of the tree-shakable RealtimePresence module to RealtimePresenceModule to avoid a clash, which I’m not very happy about.

Resolves #909.

Copy link
Member

@owenpearson owenpearson left a comment

Choose a reason for hiding this comment

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

Looks good on the whole, I do agree though that the naming should be consistent so RealtimePresenceModule isn't great. tbh I can't think of a better way to name them to avoid a conflict but I do wonder - do we really need to export all the types from both 'ably/modules' and 'ably' separately? If someone only imports types from 'ably' then they will all get stripped by the compiler anyway so it's not like we need a separate tree-shakable way to access the types?

@lawrence-forooghian
Copy link
Collaborator Author

lawrence-forooghian commented Dec 1, 2023

tbh I can't think of a better way to name them to avoid a conflict but I do wonder - do we really need to export all the types from both 'ably/modules' and 'ably' separately? If someone only imports types from 'ably' then they will all get stripped by the compiler anyway so it's not like we need a separate tree-shakable way to access the types?

I guess I thought that there were two separate variants of the library, and you used one or the other. You mean you think it'd be better for the user to just import the modules-specific stuff from ably/modules and get the types from ably?

I'm a bit confused by the word "but" though — is there a connection between your question and the naming of RealtimePresenceModule or have I misunderstood?

@lawrence-forooghian
Copy link
Collaborator Author

Thinking about it more, the types for the modular version are closely based on the way we did them for the previous Promise-based variant of the library. Correspondingly, we also have two separate versions of the TypeDoc documentation, as if they were two separate libraries. If we were to only export the types from the default variant of the library, I'm not sure what that would mean for the TypeDoc documentation for the modular variant of the library — like, where would the links to the referenced types point to if these types are not exported by the library and hence not contained in the documentation?

@owenpearson
Copy link
Member

I guess I thought that there were two separate variants of the library, and you used one or the other. You mean you think it'd be better for the user to just import the modules-specific stuff from ably/modules and get the types from ably?

Yeah I mean it's the same library at the end of the day, just different entry points for importing code. I think it's fine to import types from 'ably' and import the client from 'ably/modules'

I'm a bit confused by the word "but" though — is there a connection between your question and the naming of RealtimePresenceModule or have I misunderstood?

That I meant was that if the RealtimePresence type was in 'ably' and the RealtimePresence module was in 'ably/modules' then there wouldn't be a naming conflict, and if someone needed to import both in the same module they can choose how to resolve it themselves by using as RealtimePresenceModule or whatever

Thinking about it more, the types for the modular version are closely based on the way we did them for the previous Promise-based variant of the library. Correspondingly, we also have two separate versions of the TypeDoc documentation, as if they were two separate libraries. If we were to only export the types from the default variant of the library, I'm not sure what that would mean for the TypeDoc documentation for the modular variant of the library — like, where would the links to the referenced types point to if these types are not exported by the library and hence not contained in the documentation?

OK I don't know the workings of our typedoc setup but I'm not a fan of having this one thing named differently from everything else so if we can find a solution to this I would prefer that, do you think it's def not possible?

@lawrence-forooghian lawrence-forooghian force-pushed the 909-remove-Types-namespace branch from 4b3a1c6 to d42ccef Compare January 3, 2024 14:18
@github-actions github-actions bot temporarily deployed to staging/pull/1518/features January 3, 2024 14:18 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1518/typedoc January 3, 2024 14:19 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1518/bundle-report January 3, 2024 14:19 Inactive
@lawrence-forooghian lawrence-forooghian force-pushed the 909-remove-Types-namespace branch from d42ccef to ac4f118 Compare January 3, 2024 14:33
@github-actions github-actions bot temporarily deployed to staging/pull/1518/features January 3, 2024 14:34 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1518/bundle-report January 3, 2024 14:34 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1518/typedoc January 3, 2024 14:34 Inactive
To avoid a clash with the top-level class of the same name when we
remove the Types namespace in #909.
To avoid a clash with the top-level classes of the same name when we
remove the Types namespace in #909.
When we remove the Types namespace in #909, the RealtimePresence class
defined in ably.d.ts will clash with the variable of the same name
declared in modules.d.ts.

Owen indicated that his preference for resolving this issue is to export
the common types (i.e. those currently contained in the Types namespace)
from only the default variant and not from the modular variant, so
that’s what we do here. Users of the modular variant who wish to refer
to the common types will need to import them from the default variant.

To maintain TypeDoc’s ability to generate hyperlinks from the references
which are contained in the modular variant but which refer to the common
types (e.g. some @link tags, BaseRest’s inheritance from AbstractRest),
we switch to using a single TypeDoc project to generate documentation
for both variants.

For reasons that I don’t understand, TypeDoc is unable to resolve the
aforementioned @link tags unless I explicitly add a module source [1].
I’d have thought that it’d be sufficient to simply `import` the types
that these tags refer to, but doing so makes no difference. So, I’ve
added these module sources. Unfortunately, IntelliSense in VS Code
doesn’t know what to do with these and the link is not clickable. (I
also tried experimenting with TSDoc’s syntax for declaration references
[2] but it made no difference). I think we’ll have to live with this;
luckily there are only a few such tags.

[1] https://typedoc.org/guides/declaration-references/#module-source
[2] https://tsdoc.org/pages/tags/link/
We’re removing it because we believe that it’s more consistent with
other JS libraries for users to write `import * as Ably from 'ably'` and
then access types on the `Ably` namespace.

The triggering of @typescript-eslint/no-redeclare (and hence the added
eslint-disable-next-line statements) seems to be related to [1]. I’m not
sure why it wasn’t complaining before, though.

Resolves #909.

[1] typescript-eslint/typescript-eslint#2818
@lawrence-forooghian
Copy link
Collaborator Author

OK, I've dropped the RealtimePresenceModule renaming and added c3a2937, which implements your suggestion of exporting the common types from only the default variant.

@lawrence-forooghian
Copy link
Collaborator Author

Tests are all failing, I believe it's sandbox related. Will re-run once told it's back up.

Copy link
Member

@owenpearson owenpearson left a comment

Choose a reason for hiding this comment

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

LGTM, thanks

@lawrence-forooghian lawrence-forooghian merged commit 83c8332 into integration/v2 Jan 9, 2024
12 checks passed
@lawrence-forooghian lawrence-forooghian deleted the 909-remove-Types-namespace branch January 9, 2024 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants