-
-
Notifications
You must be signed in to change notification settings - Fork 384
Fix default exports #3248
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
base: master
Are you sure you want to change the base?
Fix default exports #3248
Conversation
i don't know what's your use case here but they are imported like this: import DataAccessHelper from '@kitware/vtk.js/IO/Core/DataAccessHelper';
// import '@kitware/vtk.js/IO/Core/DataAccessHelper/LiteHttpDataAccessHelper'; // Just need HTTP
import '@kitware/vtk.js/IO/Core/DataAccessHelper/HttpDataAccessHelper'; // HTTP + zip
// import '@kitware/vtk.js/IO/Core/DataAccessHelper/HtmlDataAccessHelper'; // html + base64 + zip
// import '@kitware/vtk.js/IO/Core/DataAccessHelper/JSZipDataAccessHelper'; // zip |
I saw that import HttpDataAccessHelper from '@kitware/vtk.js/IO/Core/DataAccessHelper/HttpDataAccessHelper';
HttpDataAccessHelper.fetchBinary(...) So should this be import DataAccessHelper from '@kitware/vtk.js/IO/Core/DataAccessHelper';
import '@kitware/vtk.js/IO/Core/DataAccessHelper/HttpDataAccessHelper';
DataAccessHelper.get('http').fetchBinary(...) instead? Or are both usages valid? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding a typecheck command!
Instead of exporting a declared const _default
and changing imports to use curly braces, you can declare a value with the same name as the interface (see the following example with HtmlDataAccessHelper), and typescript will infer the type or value:
// HtmlDataAccessHelper/index.d.ts
declare const HtmlDataAccessHelper: HtmlDataAccessHelper
export default HtmlDataAccessHelper
// other.d.ts
import HtmlDataAccessHelper from '...'
// HtmlDataAccessHelper can be used as a type or a value
toNativeType(str: string): any; | ||
extractURLParameters( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To simplify the typings, you can just do the following:
toNativeType: typeof toNativeType,
extractURLParameters: typeof extractURLParameters,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks--this is neat!
@floryst Thanks for the suggestions! I've updated my changes. However, removing the curly braces didn't work for me—I got errors like this from
|
Context
Trying to port the examples to TypeScript produces the following errors:

It turns out that default exports are misused in many places in the
.d.ts
files:.js
files don’t have types, default exports should always be values. But in some cases, aninterface
declaration is incorrectly assigned as the default export, rather than a value that conforms to that interface. This leads to the error shown in the screenshot..d.ts
files mistakenly use the default import syntax to import interfaces — which resolves to the exported const values instead of the type definitions.Results
Changes
.d.ts
files.typecheck
npm script and atsconfig.json
to ensure the.d.ts
files are consistent with each other.PR and Code Checklist
npm run reformat
to have correctly formatted codeTesting
No implementation has changed; this should only affect TypeScript-aware IDEs and build tools.