-
Notifications
You must be signed in to change notification settings - Fork 97
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
Properly encapsulate ES6 type defs. in module #346
Properly encapsulate ES6 type defs. in module #346
Conversation
@elalish This should be ready now. I tried to make it work with Monaco, but I can't figure out how; the type definitions are split into multiple files, because we need a public and private version of the Mesh and Manifold classes, but for some reason Monaco doesn't like to cross-reference type definitions. I also can't make it more usable for Monaco by merging the type definitions into a single file, because there is no way to do private type definitions in a Seems like there's 2 choices at the moment:
I also updated the cmake file to copy the new type definition files to the editor's folder. These aren't being used right now, but it should still be useful if a solution is found in the future. |
Codecov ReportPatch and project coverage have no change.
Additional details and impacted files@@ Coverage Diff @@
## master #346 +/- ##
=======================================
Coverage 91.52% 91.52%
=======================================
Files 32 32
Lines 3730 3730
=======================================
Hits 3414 3414
Misses 316 316 Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
*/ | ||
function reserveIDs(count: number): number; | ||
export type Manifold = T.Manifold; | ||
export type Mesh = T.Mesh; |
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.
So, do we actually want these? I thought this was what you removed so that new Manifold()
would correctly error?
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.
In the way it was done before, both the type and the value were exported. In the new way, Manifold and Mesh are re-exported only as a type (which is why it has export type Manifold
instead of export class Manifold
), so if you try to do new Manifold
you will now get an error. It's only a type AND value when used from a ManifoldStatic instance (which is why it's using Manifold: typeof T.Manifold
in ManifoldStatic)
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.
Ah, thank you for the explanation!
function getCircularSegments(radius: number): number; | ||
///@} | ||
import * as T from './manifold-encapsulated-types'; | ||
export * from './manifold-global-types'; |
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.
Good idea on separating these. I definitely don't want to go back to the declare
version. The first priority is getting the types right for npm users - the editor is our own problem. Maybe we could hack it a little though - I'm considering some string concatenation and replacing export
with declare
during import to the editor.
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.
I'm not sure if that would work, because Typescript really hates bundling type definitions, but it's worth a try. Maybe you could use something like dts-bundle?
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 the help!
* Properly encapsulate ES6 type defs. in module * Fixed import file name typo * Copy type definitions to editor folder (not used for now) * Dummy commit (trigger CI)
This should fix the weird discrepancy between the type definitions and the actual runtime; doing
new Manifold
instead ofnew module.Manifold
will now actually show an IDE error.I'm pretty sure this is correct now, but I'll keep this as a draft so I can take a better look into this tomorrow.