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

Getting type error (not assignable to type 'StylisPlugin') for rtlPlugin #31

Open
omareg94 opened this issue Oct 2, 2021 · 2 comments

Comments

@omareg94
Copy link

omareg94 commented Oct 2, 2021

Current Behavior 😯

When I use rtlPlugin from stylis-plugin-rtl, I get type error:
Type '(element: Element, index: number, children: (string | Element)[], callback: Middleware) => string | void' is not assignable to type 'StylisPlugin'.
image

Expected Behavior 🤔

Not having this type (TypeScript) error.

To Reproduce 🕹

Live Example (codesandbox/eager-tereshkova-lx74s)

Context 🔦

I'm trying to use rtlPlugin in order to display mui components in rtl direction.

Environment information 🌎

Simple React/Next.js. Also check Live Example above for more detailed.

  • react version: 17.0.2
  • stylis version: 4.0.10
  • stylis-plugin-rtl version: 2.1.0
  • @emotion/react version: 11.4.1
  • @emotion/styled version: 11.3.0

I have previously posted this issue at material-ui, but they reported that the bug is either within @emotion/cache or stylis-plugin-rtl (comment).
Also there's an exact issue opened at emotion-js/emotion in case the bug is there.

@amirrivand
Copy link

just edit return type on stylisRTLPlugin function in ~/node_modules/stylis-plugin-rtl/dist/stylis-rtl.d.ts like below:
declare function stylisRTLPlugin(element: MiddlewareParams[0], index: MiddlewareParams[1], children: MiddlewareParams[2], callback: MiddlewareParams[3]): string | undefined;

it works!

@iquabius
Copy link

I patched it like this:

diff --git a/node_modules/stylis-plugin-rtl/types/stylis-rtl.d.ts b/node_modules/stylis-plugin-rtl/types/stylis-rtl.d.ts
index acb55fd..f7f8791 100644
--- a/node_modules/stylis-plugin-rtl/types/stylis-rtl.d.ts
+++ b/node_modules/stylis-plugin-rtl/types/stylis-rtl.d.ts
@@ -1,3 +1,10 @@
-declare function stylisRTLPlugin(context: number, content: string): string | undefined;
+import { StylisElement, StylisPluginCallback } from "@emotion/cache";
+
+declare function stylisRTLPlugin(
+  element: StylisElement,
+  index: number,
+  children: Array<StylisElement>,
+  callback: StylisPluginCallback
+): string | void
 
 export default stylisRTLPlugin;

File in patches/stylis-plugin-rtl+2.0.2.patch

I copied the function definition from node_modules/@emotion/cache/types/index.d.ts.

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

No branches or pull requests

3 participants