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.

Why are interfaces e.g. `TableProps`, part of the top-level external API, not exported?

See original GitHub issue

Trying to define a component with an external API e.g.:

import * as React from 'react';
import { useTable } from 'react-aria';
import { useTableState } from 'react-stately';

export type ContentTableProps = TableProps & {

}

export const ContentTable: React.FC<ContentTableProps> = props => {
  return <div>

  </div>;
};

The necessary TableProps here is used in the parameters of the useTable signature, so it should be exported so I can define a new type based on it. Or just so I can create a type-safe object of it. Is there a reason it’s not exported?

TableProps here is just an example, from what I can see there are lots of exported APIs which are defined against non-exported interfaces.

FWIW Microsoft makes a TypeScript analysis tool called API Extractor; it’s Number 2 Headline Feature is designed to help detect and correct this situation: https://api-extractor.com/

Missing exports: Suppose the awesome-widgets package exports an API function AwesomeButton.draw() that requires a parameter of type DrawStyle, but you forgot to export this enum. Things seem fine at first, but when a developer tries to call that function, they discover that there’s no way to specify the DrawStyle. How to avoid these oversights?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
LFDanLucommented, Apr 29, 2022

Thanks for reporting this, this looks like something we missed on our end, I don’t see a reason why TableProps shouldn’t be exported from useTable. That tool seems promising, thanks for letting us know about it!

0reactions
craigkovatchcommented, Jun 18, 2022

I am definitely not requesting or suggesting that you export every single internal type 😃 Just those which are named in other library-level exports.

I want to sit down and look at this again so I can either revisit my assumptions or give you much clearer feedback about what the stumbling blocks were. Unfortunately I’m out sick right now, so it might be a week or two. Thanks again for jumping in.

-Craig (mobile)


From: Devon Govett @.> Sent: Friday, June 17, 2022 4:58:01 PM To: adobe/react-spectrum @.> Cc: Craig Kovatch @.>; Author @.> Subject: Re: [adobe/react-spectrum] Why are interfaces e.g. TableProps, part of the top-level external API, not exported? (Issue #3087)

This should definitely not be a blocker for anyone.

a) Type inference is often good enough. You don’t need to annotate every variable, e.g. when calling useTable and passing an options object, TypeScript already knows what the type will be so there is no need to name it. This is how we use most of the hooks ourselves. b) If you really do need a named type for some reason and it isn’t exported, you can do things like use typeof. Examplehttps://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBDAnmApnA3gVwM4oCoCGARgDYoC+cAZlBCHAOQACUKBAxjALQFTAEB6GMTIMA3ACgJSVHEKkUABVphsAHjwA+OAF44i3gRAoYKKOpkoIVODnwiUGzZoDaABgC6koA

The example for API extractor that you gave is a case where exporting the type is actually required, because it’s an enum which has runtime semantics, rather than a type that is stripped at build time. So you actually couldn’t construct an enum value without it being exported. With types, this is less of an issue, because type inference covers most cases.

I’m not sure that approach accomplishes the stated goal, though. If your API breaks/changes in the future, not exporting the typedefs doesn’t make anything safer. In fact it makes changes more difficult because the consumer doesn’t benefit from the type safety.

TypeScript is a structural type system, not a nominal one, so two types may be equivalent but have different names, or be composed of different parts nominally. For example, we often refactor types to break them apart and reuse different pieces via extends or other mechanisms. If we exported every individual type, this would no longer be possible because refactoring would become a breaking change.

We are open to exporting more types where needed, and I agree things are inconsistent today, but we need to be intentional and systematic about it.

— Reply to this email directly, view it on GitHubhttps://github.com/adobe/react-spectrum/issues/3087#issuecomment-1159309760, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACTWJEIRCWXB6IK7ZAFDZD3VPUGITANCNFSM5UUPVNUA. You are receiving this because you authored the thread.Message ID: @.***>

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot import exported interface - export not found
The root cause is in Typescript and transpilation. Once TypeScript code is transpiled, interfaces/types are gone. They don't exist anymore ...
Read more >
aws-cdk/core module
The following example will define a single top-level stack that contains ... If the AWS CDK determines that the resource is in the...
Read more >
Export interfaces that are part of the public API - Mobiscroll
Both interfaces are part of the public API of the Event Calendar component but they're not correctly exported.
Read more >
StarUML 5.0 Developer Guide (Using Open API)
This section introduces interface types that are modeling elements of StarUML™ external API, and describes their usage. Modeling elements refer to the UML ......
Read more >
The Internet Computer Interface Specification
Messages do not have a response. WebAssembly functions are exported by the WebAssembly module or provided by the System API. These are invoked...
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