Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions packages/css/src/css/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,22 +346,35 @@ if (import.meta.vitest) {

describe.concurrent("css.with()", () => {
it("css.with() with type restrictions", () => {
const myCss = css.with<{
const myCss1 = css.with<{
color: true;
background: "blue" | "grey";
border: false;
}>();

myCss({
myCss1({
color: "red", // Allow all properties
background: "blue", // Only some properties are allowed
// @ts-expect-error: border is not allowed
border: "none"
});
myCss({
myCss1({
color: "red",
// @ts-expect-error: background is allowed only "blue" or "grey"
background: "red"
});
// @ts-expect-error: color is required
myCss1({
background: "blue"
});
// @ts-expect-error: background is required
myCss1({
color: "red"
});

const myCss2 = css.with<{ size: number; radius?: number }>();
// @ts-expect-error: size is required
myCss2.raw({ radius: 10 });
});

it("Basic callback transformation", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/css/src/css/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type IsRequired<T, K extends keyof T> =
export type RestrictCSSRule<T extends CSSRule> = {
[K in keyof T as T[K] extends false ? never : K]: T[K] extends true
? K extends keyof CSSRule
? CSSRule[K]
? NonNullable<CSSRule[K]>
: never
: T[K];
} extends infer U
Expand Down