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-3857] Add typings for the tree-shakable version of the library #1498

Merged

Conversation

lawrence-forooghian
Copy link
Collaborator

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

Note: This PR is based on top of #1496; please review that one first.

This changes the way that the package does its exports, so that the user can import ably/modules, and then adds typings for the library that you get when you do this import. See commit messages for more details.

Resolves #1442.

@github-actions github-actions bot temporarily deployed to staging/pull/1498/features November 10, 2023 20:29 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1498/typedoc November 10, 2023 20:30 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1498/bundle-report November 10, 2023 20:31 Inactive
@lawrence-forooghian lawrence-forooghian force-pushed the 1442-add-typings-for-tree-shakable-version branch from 997a9b0 to 61645ad Compare November 13, 2023 13:15
@github-actions github-actions bot temporarily deployed to staging/pull/1498/features November 13, 2023 13:15 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1498/bundle-report November 13, 2023 13:16 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1498/typedoc November 13, 2023 13:17 Inactive
@lawrence-forooghian lawrence-forooghian changed the title 1442 add typings for tree shakable version Add typings for the tree-shakable version of the library Nov 13, 2023
@lawrence-forooghian lawrence-forooghian changed the title Add typings for the tree-shakable version of the library [SDK-3719] Add typings for the tree-shakable version of the library Nov 13, 2023
@lawrence-forooghian lawrence-forooghian changed the title [SDK-3719] Add typings for the tree-shakable version of the library [SDK-3857] Add typings for the tree-shakable version of the library Nov 13, 2023
@lawrence-forooghian lawrence-forooghian force-pushed the 1442-add-typings-for-tree-shakable-version branch from 61645ad to 3463ae3 Compare November 13, 2023 13:24
@github-actions github-actions bot temporarily deployed to staging/pull/1498/features November 13, 2023 13:24 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1498/typedoc November 13, 2023 13:25 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1498/bundle-report November 13, 2023 13:25 Inactive
@lawrence-forooghian lawrence-forooghian marked this pull request as ready for review November 13, 2023 14:45
@lawrence-forooghian lawrence-forooghian force-pushed the 1442-add-typings-for-tree-shakable-version branch from 3463ae3 to 2ccb5eb Compare November 14, 2023 18:42
@github-actions github-actions bot temporarily deployed to staging/pull/1498/features November 14, 2023 18:43 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1498/typedoc November 14, 2023 18:44 Inactive
@lawrence-forooghian lawrence-forooghian force-pushed the 1442-add-typings-for-tree-shakable-version branch from 2ccb5eb to 869be09 Compare November 14, 2023 18:44
@github-actions github-actions bot temporarily deployed to staging/pull/1498/features November 14, 2023 18:44 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1498/bundle-report November 14, 2023 18:45 Inactive
@lawrence-forooghian lawrence-forooghian force-pushed the 1489-remove-remaining-REST-code-from-BaseRealtime branch from cf1d07a to b75eb5b Compare November 14, 2023 19:04
These declarations are unreachable via the typings. The user needs to
access these methods via the MessageStatic and PresenceMessageStatic
interfaces.
These declarations are unreachable via the typings.
This allows users to import the module-based version by writing

```
import { BaseRealtime } from 'ably/modules'
```

instead of having to import 'ably/build/modules'.

I followed the guidance in [1] and [2].

[1] https://nodejs.org/api/packages.html#exports
[2] https://webpack.js.org/guides/package-exports/
I wasn’t sure of the best way to approach the typings of the modules
(`Rest` etc). They should be opaque to the user (they shouldn’t be
interacting with them directly and we want be free to change their
interface in the future).

There is an open issue to add support for opaque types to TypeScript
[1], and people have suggested various sorts of ways of approximating
them, which revolve around the use of `unique symbol` declarations.
However, I don’t fully understand these solutions and so thought it best
not to include them in our public API. So, for now, let’s just use
`unknown`, the same way as we do for `CipherParams.key`.

Resolves #1442.

[1] microsoft/TypeScript#202
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 great!

Base automatically changed from 1489-remove-remaining-REST-code-from-BaseRealtime to integration/v2 November 21, 2023 00:17
@lawrence-forooghian lawrence-forooghian merged commit a47c23d into integration/v2 Nov 21, 2023
12 checks passed
@lawrence-forooghian lawrence-forooghian deleted the 1442-add-typings-for-tree-shakable-version branch November 21, 2023 00:18
@VeskeR VeskeR mentioned this pull request Mar 1, 2024
10 tasks
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