question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Export more TypeScript types at package root level

See original GitHub issue

Is 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:open
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
raymondfengcommented, May 19, 2021

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:

import {Account as NearAccount} from 'near-api-js';
0reactions
vgrichinacommented, May 25, 2021

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 formatNearAmount directly on top level instead of having to look where it is located every time.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found