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

warn parameter is not compatible with Error anymore #4754

Closed
Shinigami92 opened this issue Dec 15, 2022 · 4 comments · Fixed by #4757
Closed

warn parameter is not compatible with Error anymore #4754

Shinigami92 opened this issue Dec 15, 2022 · 4 comments · Fixed by #4757

Comments

@Shinigami92
Copy link
Contributor

Expected Behavior / Situation

I need to update one of my plugins from Vite 3 to 4 and therefore the underlying Rollup version was migrated to v3

Previously it was possible to pass an error to a Rollup warn call.

https://github.com/Shinigami92/vite-plugin-time-reporter/pull/26/files#diff-a2a171449d862fe29692ce031981047d7ab755ae7f84c707aef80701b3ea0c80R43

Now this is not the case anymore 🙁

Actual Behavior / Situation

There was a change that changed the RollupLog['name'] property to names

names?: string[];

https://github.com/rollup/rollup/pull/4579/files#diff-2651238122dc82e0e84b4e3cb1499b8cbd4c01a21a36c9c2fae5812e95cd8ec8L35-R26

This might result in that RollupLog is now not anymore compatible with the Error interface

Modification Proposal

Could we change it back to accept Error for warn calls?
This could help in that many Vite plugins out there that are just "simple" can just support Vite 2, 3 and 4 without any runtime changes and therefore don't need to introduce a breaking change just for a warn call.

@lukastaegert
Copy link
Member

The name property has special meaning for errors and is something very different from the names property that some errors or warnings can have.

Could you please describe in words that have more information than "does not work" what exactly is not working for your when you pass an error as a warning? Is it just a TypeScript issue? It works, but the CLI output is not what you expect? Something else? If it is a TypeScript error, does it work when you cast to any?

Changing errors back is not really an option, this was a big refactoring to unify and simplify many errors and warnings in Rollup 3, so some issues for plugins cannot be avoided, unfortunately.

@Shinigami92
Copy link
Contributor Author

Shinigami92 commented Dec 15, 2022

The message is:

Argument of type 'Error' is not assignable to parameter of type 'string | RollupLog'.
  Type 'Error' is not assignable to type 'RollupLog'.
    Types of property 'cause' are incompatible.
      Type 'unknown' is not assignable to type 'Error | undefined'.ts(2345)

Oh, so it's not the name?: string but the cause property!

In lib.es2022.error.d.ts Error is defined with:

interface Error {
    cause?: unknown;
}

When I manipulate node_modules/.pnpm/rollup@3.7.3/node_modules/rollup/dist/rollup.d.ts line 22 to allow cause?: Error | unknown; TS doesn't show up any error 🙌

@lukastaegert Would this be an allowed modification to Rollup?
Should I provide a PR? Or can you fix it just directly on your side?

This change would fulfill my Modification Proposal:

This could help in that many Vite plugins out there that are just "simple" can just support Vite 2, 3 and 4 without any runtime changes and therefore don't need to introduce a breaking change just for a warn call.

@lukastaegert
Copy link
Member

If lib.es2022.error.d.ts defines cause as unknown, then I think it is fine to change it to just unknown. Error | unknown does not really make sense as it would be equivalent to unknown anyway as I understand it.
So yes, PR welcome!

@rollup-bot
Copy link
Collaborator

This issue has been resolved via #4757 as part of rollup@3.7.5. You can test it via npm install rollup.

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

Successfully merging a pull request may close this issue.

3 participants