Skip to content

Commit

Permalink
🐛 fix: 修正类型定义调整后 ()=>css`` 的使用方式类型定义不正确的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Feb 4, 2023
1 parent 44a6ad2 commit 823ea12
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/types/genericUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ export type BaseReturnType = KVObject | AtomInputType;

type KVObject = Record<string, CSSObject | string | SerializedStyles>;

type StyleObjectOnly<T extends BaseReturnType> = T extends string ? never : T;
type StyleObjectOnly<T extends BaseReturnType> = T extends string
? never
: T extends SerializedStyles
? never
: T;

/**
* 根据用户输入的样式对象,导出可以给用户使用消费的类型泛型
Expand All @@ -30,10 +34,12 @@ type DefinitionToResult<T, K extends keyof T = keyof T> = {
};

/**
* 根据用户返回的样式对象,返回一个可以给用户使用的
* 譬如用户输入为 { a: css`color: red;`, b: { color: 'red' }
* 根据用户返回的样式对象,返回一个可以给用户使用的类型定义
* 用户输入为 { a: css`color: red;`, b: { color: 'red' }
* 输出的类型泛型为 { a:string; b:string }
*/
export type ReturnStyleToUse<T extends BaseReturnType> = T extends string
? T
: T extends SerializedStyles
? string
: DefinitionToResult<StyleObjectOnly<T>>;

0 comments on commit 823ea12

Please sign in to comment.