-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
feat: allows import core version in typescript #1713
Conversation
Hi, thank you for your contribution. |
Paper by default export paper-full which is has acorn, PaperScript, and all this beautiful staff, which is not always really needed (see paperjs/paper.js#which-version-to-use). I needed a way to import core version of the lib, but I did loose typings. This file will allow to import paper-core with typings as default. Which is not perfect solution, but it's works. There is a limitation on re-exporting modules with Tests should be exacly like in If you think this solution is worth it, I will add tests. |
Also, can re-export all named exports manually, like: import paper, { Color } from 'paper';
export default paper;
export { Color }; |
I think that the best way to figure out if this is needed would be to set up a project reproducing the issue (using paper-core in a TypeScript project but losing typings) and see if this is the best way to solve it or if there is another workaround. |
Ok, here it is. As you can see there is no typings for core version. |
@sasensi I did found out if I add to |
@anion155, thank you for the reproduction case, it is much clearer for me now. Your last solution seems cleaner than your first proposal, but indeed, This is the first time that I face this pattern (multiple possible exports of a library) so I don't know yet how to achieve that. |
@anion155, I think that I found a solution based on my idea of splitting the declaration in 2 parts. |
Just a tip. Do not forget to actually add file |
Typings were missing when importing paper core version with: `import * as paper from 'paper/dist/paper-core'` syntax. This changes the generated TypeScript definition so that it exports two modules: `paper` and `paper/dist/paper-core`. In the same logic, `paper-core.d.ts` file is added to make sure that the corresponding definition is automatically loaded. This also takes care of the fact that `PaperScript` class is not available in paper core version, by removing it from the corresponding TypeScript definition. Finally, this also simplifies existing definition by directly exporting a `PaperScope` instance as the module instead of duplicating all `PaperScope` properties and methods on the module itself. Closes paperjs#1713
* Allow paper core import in TypeScript Typings were missing when importing paper core version with: `import * as paper from 'paper/dist/paper-core'` syntax. This changes the generated TypeScript definition so that it exports two modules: `paper` and `paper/dist/paper-core`. In the same logic, `paper-core.d.ts` file is added to make sure that the corresponding definition is automatically loaded. This also takes care of the fact that `PaperScript` class is not available in paper core version, by removing it from the corresponding TypeScript definition. Finally, this also simplifies existing definition by directly exporting a `PaperScope` instance as the module instead of duplicating all `PaperScope` properties and methods on the module itself. Closes #1713
Description
Allows typescript users to import core version of paper as
import paper from 'paper/dist/paper-core';
Checklist
npm run jshint
passes)