Export more TypeScript types at package root level
See original GitHub issueIs your feature request related to a problem? Please describe.
When we use near-api-js in TypeScript, we have to find out individual sub-directories inside the package to import types.
import
{Account, KeyPair, Near, utils}
from 'near-api-js';
import
{ InMemoryKeyStore, UnencryptedFileSystemKeyStore, }
from 'near-api-js/lib/key_stores';
import
{NearConfig}
from 'near-api-js/lib/near';
import
{ FinalExecutionOutcome, JsonRpcProvider, }
from 'near-api-js/lib/providers';
import
{ ExecutionStatusBasic, FinalExecutionStatusBasic, Finality, }
from 'near-api-js/lib/providers/provider';
import
{ addKey, createAccount, fullAccessKey, transfer, }
from 'near-api-js/lib/transaction';
import
{PublicKey}
from 'near-api-js/lib/utils';
import
{parseNearAmount}
from 'near-api-js/lib/utils/format';
import
{base_decode}
from 'near-api-js/lib/utils/serialize';
Describe the solution you’d like
We would like to import such types from the package directly, such as:
import
{Account, KeyPair, Near, utils, InMemoryKeyStore, UnencryptedFileSystemKeyStore, NearConfig, FinalExecutionOutcome, JsonRpcProvider, }
from 'near-api-js';
If you really want to separate such types, please use TypeScript namespaces:
export namespace keys {
export class PublicKey {}
}
Describe alternatives you’ve considered See my imports above.
Additional context Add any other context or screenshots about the feature request here.
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
javascript - How do I export multiple interfaces in a nested way ...
I have a pretty large npm module written in TypeScript, which exposes a number of types, including several interfaces.
Read more >Documentation - Modules .d.ts - TypeScript
Testing your types · Create a new file in the root of your source tree: [libname].d.ts · Add declare module "[libname]" { }...
Read more >using package exports fields can result in incompatible types ...
TypeScript thinks that the types are incompatible, even though they are both referencing the same file in the package. This exact same ...
Read more >How To Use Modules in TypeScript | DigitalOcean
How To Use Modules in TypeScript · Modules are a way to organize your code into smaller, more manageable pieces, allowing programs to...
Read more >Mocha - the fun, simple, flexible JavaScript test framework
Installation; Getting Started; Run Cycle Overview; Detects Multiple Calls to done() ... Set up a test script in package.json: ... Root-Level Hooks.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

My first preference is to export public facing types at root level. Namespaces can be used for more isolations if needed. Please note that exported artifacts from a package does not create global conflicts as they be imported as a different name. For example:
I think that flattening interfaces would be pretty good idea for both near-api-js and near-sdk-as.
Like there isn’t that much stuff in these libraries to create separate subnamespaces, they exist mostly for historical reasons and generally just result in extra inconvenience. And if anything it’s best to avoid name clashes for public classes / functions in one library in any case, as it would confuse users.
I pretty much would prefer to import stuff like
formatNearAmountdirectly on top level instead of having to look where it is located every time.