Skip to content
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

unable to use any plugins with Typescript #231

Closed
peterhalicky opened this issue Aug 17, 2022 · 14 comments · Fixed by #232
Closed

unable to use any plugins with Typescript #231

peterhalicky opened this issue Aug 17, 2022 · 14 comments · Fixed by #232
Labels

Comments

@peterhalicky
Copy link

peterhalicky commented Aug 17, 2022

It is not possible to use any of the provided plugins with Typescript (well - I've tried two). The following code:

import jsep from 'jsep';
import comment from '@jsep-plugin/comment';
import assignment from '@jsep-plugin/assignment';
jsep.plugins.register(comment);
jsep.plugins.register(assignment);

Produces errors by tsc:

index.ts:4:23 - error TS2345: Argument of type 'typeof import("/Users/.../jsep-plugin-issue/node_modules/@jsep-plugin/comment/types/tsd")' is not assignable to parameter of type 'IPlugin'.
  Types of property 'init' are incompatible.
    Type '(this: typeof jsep) => void' is not assignable to type '(this: typeof import("jsep")) => void'.
      The 'this' types of each signature are incompatible.
        Property 'default' is missing in type 'typeof import("jsep")' but required in type 'typeof jsep'.

4 jsep.plugins.register(comment);
                        ~~~~~~~

index.ts:5:23 - error TS2345: Argument of type 'typeof import("/Users/.../jsep-plugin-issue/node_modules/@jsep-plugin/assignment/types/tsd")' is not assignable to parameter of type 'IPlugin'.
  Types of property 'init' are incompatible.
    Type '(this: typeof jsep) => void' is not assignable to type '(this: typeof import("jsep")) => void'.
      The 'this' types of each signature are incompatible.
        Property 'default' is missing in type 'typeof import("jsep")' but required in type 'typeof jsep'.

5 jsep.plugins.register(assignment);
                        ~~~~~~~~~~


Found 2 errors in the same file, starting at: index.ts:4

The only way I found to work around this is to use jsep.plugins.register(comment as unknown as IPlugin), although that seems to be a bit ugly.

When I modified the plugin's tsd.d.ts and changed the first line import * as jsep from 'jsep'; to import jsep from 'jsep'; then the compiler error disappeared. This is probably the way to fix the issue, although I will leave it to the authors to decide if that is the right solution.

Code/project to reproduce the problem can be found here: https://github.com/peterhalicky/jsep-plugin-issue

@6utt3rfly
Copy link
Collaborator

@peterhalicky - the import jsep from 'jsep' (vs import * as jsep from 'jsep') would require the esModuleInterop typescript option enabled... which might not be so bad since the readme indicates examples of that form.

Alternately, I tried this and it seems to work:, and it might have less impact to existing users

import * as jsep from 'jsep';
import { IPlugin } from 'jsep';
// ...plugin

declare const _export: IPlugin;
export default _export;

Any thoughts on something like this?

@peterhalicky
Copy link
Author

peterhalicky commented Aug 22, 2022

I'm no expert on TS, but if I understand this correctly, you redeclare the type of the export to be IPlugin, essentially doing more of what I did as a workaround (xyz as unknown as IPlugin), right? Either way, I do not feel competent to judge if this is the right solution - but if it works, it's good enough for me.
(Note: I do have the esModuleInterop option enabled)

github-actions bot pushed a commit that referenced this issue Sep 18, 2022
## [1.3.7](v1.3.6...v1.3.7) (2022-09-18)

### Bug Fixes

* add "types" export ([505a81a](505a81a))
* export default IPlugin from all plugins ([cd38da5](cd38da5)), closes [#231](#231)
@github-actions
Copy link

🎉 This issue has been resolved in version 1.3.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

github-actions bot pushed a commit that referenced this issue Sep 18, 2022
# [@jsep-plugin/arrow-v1.0.5](https://github.com/EricSmekens/jsep/compare/@jsep-plugin/arrow-v1.0.4...@jsep-plugin/arrow-v1.0.5) (2022-09-18)

### Bug Fixes

* export default IPlugin from all plugins ([cd38da5](cd38da5)), closes [#231](#231)
@github-actions
Copy link

🎉 This issue has been resolved in version @jsep-plugin/arrow-v1.0.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

github-actions bot pushed a commit that referenced this issue Sep 18, 2022
# [@jsep-plugin/assignment-v1.2.1](https://github.com/EricSmekens/jsep/compare/@jsep-plugin/assignment-v1.2.0...@jsep-plugin/assignment-v1.2.1) (2022-09-18)

### Bug Fixes

* export default IPlugin from all plugins ([cd38da5](cd38da5)), closes [#231](#231)
@github-actions
Copy link

🎉 This issue has been resolved in version @jsep-plugin/assignment-v1.2.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

github-actions bot pushed a commit that referenced this issue Sep 18, 2022
# [@jsep-plugin/async-await-v1.0.2](https://github.com/EricSmekens/jsep/compare/@jsep-plugin/async-await-v1.0.1...@jsep-plugin/async-await-v1.0.2) (2022-09-18)

### Bug Fixes

* export default IPlugin from all plugins ([cd38da5](cd38da5)), closes [#231](#231)
@github-actions
Copy link

🎉 This issue has been resolved in version @jsep-plugin/async-await-v1.0.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

github-actions bot pushed a commit that referenced this issue Sep 18, 2022
# [@jsep-plugin/comment-v1.0.3](https://github.com/EricSmekens/jsep/compare/@jsep-plugin/comment-v1.0.2...@jsep-plugin/comment-v1.0.3) (2022-09-18)

### Bug Fixes

* export default IPlugin from all plugins ([cd38da5](cd38da5)), closes [#231](#231)
@github-actions
Copy link

🎉 This issue has been resolved in version @jsep-plugin/comment-v1.0.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

github-actions bot pushed a commit that referenced this issue Sep 18, 2022
# [@jsep-plugin/new-v1.0.2](https://github.com/EricSmekens/jsep/compare/@jsep-plugin/new-v1.0.1...@jsep-plugin/new-v1.0.2) (2022-09-18)

### Bug Fixes

* export default IPlugin from all plugins ([cd38da5](cd38da5)), closes [#231](#231)
@github-actions
Copy link

🎉 This issue has been resolved in version @jsep-plugin/new-v1.0.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

github-actions bot pushed a commit that referenced this issue Sep 18, 2022
# [@jsep-plugin/numbers-v1.0.1](https://github.com/EricSmekens/jsep/compare/@jsep-plugin/numbers-v1.0.0...@jsep-plugin/numbers-v1.0.1) (2022-09-18)

### Bug Fixes

* export default IPlugin from all plugins ([cd38da5](cd38da5)), closes [#231](#231)
@github-actions
Copy link

🎉 This issue has been resolved in version @jsep-plugin/numbers-v1.0.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

github-actions bot pushed a commit that referenced this issue Sep 18, 2022
# [@jsep-plugin/object-v1.2.1](https://github.com/EricSmekens/jsep/compare/@jsep-plugin/object-v1.2.0...@jsep-plugin/object-v1.2.1) (2022-09-18)

### Bug Fixes

* export default IPlugin from all plugins ([cd38da5](cd38da5)), closes [#231](#231)
@github-actions
Copy link

🎉 This issue has been resolved in version @jsep-plugin/object-v1.2.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

github-actions bot pushed a commit that referenced this issue Sep 18, 2022
# [@jsep-plugin/regex-v1.0.3](https://github.com/EricSmekens/jsep/compare/@jsep-plugin/regex-v1.0.2...@jsep-plugin/regex-v1.0.3) (2022-09-18)

### Bug Fixes

* export default IPlugin from all plugins ([cd38da5](cd38da5)), closes [#231](#231)
@github-actions
Copy link

🎉 This issue has been resolved in version @jsep-plugin/regex-v1.0.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

github-actions bot pushed a commit that referenced this issue Sep 18, 2022
# [@jsep-plugin/spread-v1.0.2](https://github.com/EricSmekens/jsep/compare/@jsep-plugin/spread-v1.0.1...@jsep-plugin/spread-v1.0.2) (2022-09-18)

### Bug Fixes

* export default IPlugin from all plugins ([cd38da5](cd38da5)), closes [#231](#231)
@github-actions
Copy link

🎉 This issue has been resolved in version @jsep-plugin/spread-v1.0.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

github-actions bot pushed a commit that referenced this issue Sep 18, 2022
# [@jsep-plugin/template-v1.0.2](https://github.com/EricSmekens/jsep/compare/@jsep-plugin/template-v1.0.1...@jsep-plugin/template-v1.0.2) (2022-09-18)

### Bug Fixes

* export default IPlugin from all plugins ([cd38da5](cd38da5)), closes [#231](#231)
@github-actions
Copy link

🎉 This issue has been resolved in version @jsep-plugin/template-v1.0.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

github-actions bot pushed a commit that referenced this issue Sep 18, 2022
# [@jsep-plugin/ternary-v1.1.3](https://github.com/EricSmekens/jsep/compare/@jsep-plugin/ternary-v1.1.2...@jsep-plugin/ternary-v1.1.3) (2022-09-18)

### Bug Fixes

* export default IPlugin from all plugins ([cd38da5](cd38da5)), closes [#231](#231)
@github-actions
Copy link

🎉 This issue has been resolved in version @jsep-plugin/ternary-v1.1.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants