Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit 47aeed6

Browse files
committed
fix(types*): Made the property throw an error
1 parent 447371c commit 47aeed6

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed
Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
import type { CustomCSSProperties } from './custom-css-properties';
2+
import { MediaQuery } from './custom-html-type';
23

3-
export type ClassesObjectType = {
4-
[key: string]:
5-
| CustomCSSProperties
6-
| {
7-
[className: string]: CustomCSSProperties | ClassesObjectType;
8-
};
9-
};
4+
export type ClassesObjectType =
5+
| {
6+
[key in MediaQuery]:
7+
| CustomCSSProperties
8+
| {
9+
[className: string]: CustomCSSProperties;
10+
};
11+
}
12+
| {
13+
[className: string]: CustomCSSProperties;
14+
};
15+
16+
type Exact<T, U> = T extends U ? T : never;
1017

1118
export type ExactClassesObjectType<T> = {
12-
[K in keyof T | string]: K extends keyof T ? T[K] : CustomCSSProperties | ClassesObjectType;
19+
[K in keyof T | string]: K extends keyof T ? Exact<T[K], CustomCSSProperties> : CustomCSSProperties;
1320
};

src/_internal/types/custom/custom-html-type.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type AtKeyframes = {
3535
[K in `@keyframes ${string}`]: KeyframesDefinition;
3636
};
3737

38-
type MediaQuery = `@media ${string}`;
38+
export type MediaQuery = `@media ${string}`;
3939
export type MediaQueryType = {
4040
[key in MediaQuery]?: CustomCSSProperties | AtKeyframes;
4141
};

src/core/method/create.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { sheetCompiler, isInDevelopment, injectCSS, genBase62Hash } from '../../
33
import styles from '../styles/style.module.css';
44
import { createGlobalStyleSheetPromise, globalStyleSheetPromise, resolveGlobalStyleSheet } from './create-build-in-helper';
55

6-
export function create<T extends ClassesObjectType>(object: ExactClassesObjectType<T>): ReturnStyleType<T> {
6+
export function create<T extends ClassesObjectType>(object: ExactClassesObjectType<T> | ClassesObjectType): ReturnStyleType<T> {
77
const base62Hash = genBase62Hash(object, 5);
88
const { styleSheet } = sheetCompiler(object, base62Hash);
99
if (typeof globalStyleSheetPromise === 'undefined') createGlobalStyleSheetPromise();

src/core/style.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { global } from './method/global';
55
import { root } from './method/root';
66

77
class Style {
8-
static create<T extends ClassesObjectType>(object: ExactClassesObjectType<T>): ReturnStyleType<T> {
8+
static create<T extends ClassesObjectType>(object: ExactClassesObjectType<T> | ClassesObjectType): ReturnStyleType<T> {
99
return create(object);
1010
}
1111
static set(object: CustomCSSProperties): string {

0 commit comments

Comments
 (0)