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

Module subpathing required to import types #411

Open
yo1dog opened this issue Oct 14, 2024 · 1 comment
Open

Module subpathing required to import types #411

yo1dog opened this issue Oct 14, 2024 · 1 comment
Assignees
Labels
priority: medium This PR should be reviewed after all high priority PRs. status: in progress This issue is being worked on. type: chore This PR contains changes that are not covered by other types (stylistic, dependency updates, etc).

Comments

@yo1dog
Copy link

yo1dog commented Oct 14, 2024

To import types, one must import them from module subpaths. This ties projects to the module's internal file structure, which is against best practices, and could make any internal file renaming/restructuring a breaking change.

Instead, you could expose the types from the module root using a namespace as described in #410.

For example, currently one must:

import type {FetchedMessage} from 'pubnub/lib/types/core/types/api/history';

Using the namespace you could instead do:

declare namespace PubNub {
  export * from '../core/types/api/history';
  ...
}
import {FetchedMessage} from 'pubnub';

Or, keeping the types namespaced:

declare namespace PubNub {
  export * as History from '../core/types/api/history';
  ...
}
import * as PubNub from 'pubnub';
let myMessages: PubNub.History.FetchedMessage[];
@parfeon
Copy link
Contributor

parfeon commented Oct 29, 2024

Created a script which will merge all type definitions created by tsc into a single file.
Common types (for whole library) part of the root PubNub namespace and specific API grouped under respective nested namespaces.

import PubNub, {PubNubConfiguration, Publish, History} from 'pubnub';

// PubNub client configuration.
let configuration: PubNubConfiguration = {
  publishKey: 'secret', 
  subscribeKey: 'secret', 
  userId: 'user-1'
}; 

// Fetch messages configuration.
let fetchParameter: History.FetchMessagesParameters = {
  channels: ['channel-1']
};

@parfeon parfeon self-assigned this Oct 29, 2024
@parfeon parfeon added status: in progress This issue is being worked on. priority: medium This PR should be reviewed after all high priority PRs. type: chore This PR contains changes that are not covered by other types (stylistic, dependency updates, etc). labels Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: medium This PR should be reviewed after all high priority PRs. status: in progress This issue is being worked on. type: chore This PR contains changes that are not covered by other types (stylistic, dependency updates, etc).
Projects
None yet
Development

No branches or pull requests

2 participants