-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
4.8.2: Type serialization error with unique symbol #50720
Comments
@typescript-bot bisect good v4.7.4 bad v4.8.2 |
The change between v4.7.4 and v4.8.2 occurred at bf5acb5. |
Bah, no, that isn't right. |
Thanks @jakebailey that looks directly related. This is the workaround I used to solve the linked issue. type WithPropertyValue<P> = {
readonly [K in $$Sym]: P
}
export type PropertyValue<Property extends keyof CSSProperties, Config = null> = (
Config extends null
? WithPropertyValue<Property>
: Config extends { [K: string]: any }
? CSS<Config['utils']>[Property]
: never
) This avoids serializing the late-bound name ( If this is the only path forward, it seems like an acceptable tradeoff, especially given the complexity of the types in this library. I mostly wanted to validate that this was a deliberate change and not a regression. |
It seems like this is a known limitation, but I can’t bring myself to label it “working as intended.” It’s pretty weird and seems like we ought to be able to do better, but maybe it would take a lot of work. |
When will this issue be fixed |
This comment was marked as spam.
This comment was marked as spam.
can you please explain how to implement it? |
@AlmogCHEQ You need to patch stitches. Something like this: diff --git a/types/css-util.d.ts b/types/css-util.d.ts
index 1668fc2ab56c421894c547b2e5a988166cd90e5f..cfdad3f208ef7f57c89de7fb94cdaecbd7378c63 100644
--- a/types/css-util.d.ts
+++ b/types/css-util.d.ts
@@ -117,3 +117,11 @@ export type $$ScaleValue = typeof $$ScaleValue
export declare const $$ThemeValue: unique symbol
export type $$ThemeValue = typeof $$ThemeValue
+
+// https://github.com/microsoft/TypeScript/issues/37888#issuecomment-846638356
+export type WithPropertyValue<T> = {
+ readonly [K in $$PropertyValue]: T
+}
+export type WithScaleValue<T> = {
+ readonly [K in $$ScaleValue]: T;
+}
\ No newline at end of file
diff --git a/types/index.d.ts b/types/index.d.ts
index 8dbcc9cad3f6c556a3f370065dd95300a02dd973..dafadd22e8b6285aadee2630936a7918c9c5b02b 100644
--- a/types/index.d.ts
+++ b/types/index.d.ts
@@ -35,7 +35,7 @@ export type ComponentProps<Component> = Component extends ((...args: any[]) => a
/** Returns a type that expects a value to be a kind of CSS property value. */
export type PropertyValue<Property extends keyof CSSUtil.CSSProperties, Config = null> = (
Config extends null
- ? { readonly [K in CSSUtil.$$PropertyValue]: Property }
+ ? CSSUtil.WithPropertyValue<Property>
: Config extends { [K: string]: any }
? CSSUtil.CSS<
Config['media'],
@@ -49,7 +49,7 @@ export type PropertyValue<Property extends keyof CSSUtil.CSSProperties, Config =
/** Returns a type that expects a value to be a kind of theme scale value. */
export type ScaleValue<Scale, Config = null> = (
Config extends null
- ? { readonly [K in CSSUtil.$$ScaleValue]: Scale }
+ ? CSSUtil.WithScaleValue<Scale>
: Config extends { [K: string]: any }
? Scale extends keyof Config['theme']
? `$${string & keyof Config['theme'][Scale]}` |
Any word on this?? I'm seeing this highlighted in VSCode with TS 5.0.4 (in |
Currently running into this error now. Should we just not use symbols here? |
To anyone fighting with this, here is a step-by-step solution: |
Bug Report
Original issue: stitchesjs/stitches#1078
When two types refer to the same unique symbol and they are combined via inference, exporting the inferred type results in a 4118 serialization error.
🔎 Search Terms
Unique symbol, serialized, error, 4118
🕗 Version & Regression Information
⏯ Playground Link
Workbench Repro
🙁 Actual behavior
Error: The type of this node cannot be serialized because its property '[$$Sym]' cannot be serialized.(4118)
🙂 Expected behavior
No error.
The text was updated successfully, but these errors were encountered: