Skip to content

Commit 3eabe0d

Browse files
lkostrowskiclaude
andcommitted
fix(graphiql): type the theme custom properties instead of casting
GraphiQL/shared.tsx has no `@ts-strict-ignore`, unlike the two files its code came from, so `tsc-strict` caught what the `as React.CSSProperties` cast in useDashboardTheme had been hiding: the cast erased the custom-property keys, making every `rootStyle["--font-size-*"]` read an implicit any. Declared the type instead of asserting it, per the repo's TypeScript style. Intersecting with CSSProperties keeps `style={rootStyle}` assignable at the three call sites while the Record half types the indexed reads. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent a84882e commit 3eabe0d

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

src/components/GraphiQL/styles.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,32 @@ export const useEditorStyles = () => {
6565
};
6666
};
6767

68+
/**
69+
* GraphiQL is sized and coloured through CSS custom properties. React's
70+
* `CSSProperties` does not know about custom properties, so intersect it to
71+
* keep both the `style={...}` assignability and the indexed reads.
72+
*/
73+
type DashboardThemeStyle = React.CSSProperties &
74+
Record<
75+
| "--font-size-body"
76+
| "--font-size-h2"
77+
| "--font-size-h3"
78+
| "--font-size-h4"
79+
| "--font-weight-regular"
80+
| "--font-size-hint"
81+
| "--font-size-inline-code"
82+
| "--color-base",
83+
string
84+
>;
85+
6886
export const useDashboardTheme = () => {
6987
const {
7088
themeValues: {
7189
colors: { background },
7290
},
7391
} = useTheme();
7492
const match = background.default1.match(/hsla\(([^)]+)\)/);
75-
const rootStyle = {
93+
const rootStyle: DashboardThemeStyle = {
7694
"--font-size-body": vars.fontSize[4],
7795
"--font-size-h2": vars.fontSize[6],
7896
"--font-size-h3": vars.fontSize[5],
@@ -81,7 +99,7 @@ export const useDashboardTheme = () => {
8199
"--font-size-hint": vars.fontSize[5],
82100
"--font-size-inline-code": vars.fontSize[3],
83101
"--color-base": match ? match[1] : background.default1,
84-
} as React.CSSProperties;
102+
};
85103

86104
return { rootStyle };
87105
};

0 commit comments

Comments
 (0)