Skip to content

Commit 216f6e1

Browse files
committed
Fix: CSS - More strict required check css.with() #226
1 parent 60ebee5 commit 216f6e1

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

packages/css/src/css/index.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,22 +346,35 @@ if (import.meta.vitest) {
346346

347347
describe.concurrent("css.with()", () => {
348348
it("css.with() with type restrictions", () => {
349-
const myCss = css.with<{
349+
const myCss1 = css.with<{
350350
color: true;
351351
background: "blue" | "grey";
352352
border: false;
353353
}>();
354354

355-
myCss({
355+
myCss1({
356356
color: "red", // Allow all properties
357357
background: "blue", // Only some properties are allowed
358358
// @ts-expect-error: border is not allowed
359359
border: "none"
360360
});
361-
myCss({
361+
myCss1({
362+
color: "red",
362363
// @ts-expect-error: background is allowed only "blue" or "grey"
363364
background: "red"
364365
});
366+
// @ts-expect-error: color is required
367+
myCss1({
368+
background: "blue"
369+
});
370+
// @ts-expect-error: background is required
371+
myCss1({
372+
color: "red"
373+
});
374+
375+
const myCss2 = css.with<{ size: number; radius?: number }>();
376+
// @ts-expect-error: size is required
377+
myCss2.raw({ radius: 10 });
365378
});
366379

367380
it("Basic callback transformation", () => {

packages/css/src/css/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ type IsRequired<T, K extends keyof T> =
99
export type RestrictCSSRule<T extends CSSRule> = {
1010
[K in keyof T as T[K] extends false ? never : K]: T[K] extends true
1111
? K extends keyof CSSRule
12-
? CSSRule[K]
12+
? NonNullable<CSSRule[K]>
1313
: never
1414
: T[K];
1515
} extends infer U

0 commit comments

Comments
 (0)