diff --git a/src/functions/createStyish.ts b/src/functions/createStyish.ts index 693d9080..d988d9d5 100644 --- a/src/functions/createStyish.ts +++ b/src/functions/createStyish.ts @@ -4,12 +4,18 @@ import { createStyles, StyleOrGetStyleFn } from './createStyles'; /** * 业务应用中创建复合通用样式的进阶 */ -export function createStylish(cssStyleOrGetCssStyleFn: StyleOrGetStyleFn) { +export function createStylish( + cssStyleOrGetCssStyleFn: StyleOrGetStyleFn, +) { + // FIXME :类型定义 + // @ts-ignore const useStyles = createStyles(cssStyleOrGetCssStyleFn); - return (props?: Props): ReturnStyleToUse => { + return (props?: Props): ReturnStyleToUse => { const { styles } = useStyles(props); + // FIXME :类型定义 + // @ts-ignore return styles; }; } diff --git a/src/functions/createStyles.ts b/src/functions/createStyles.ts index f3b23356..2f73e7ac 100644 --- a/src/functions/createStyles.ts +++ b/src/functions/createStyles.ts @@ -29,17 +29,18 @@ export type StyleOrGetStyleFn = StyleDefinition | GetStyleFn = (theme: CreateStylesTheme, props?: P) => StyleDefinition; -export type UseStyleS = (props?: P) => ReturnStyles; +export type UseStyleHook = (props?: P) => ReturnStyles; interface CreateStylesFn { - (style: StyleDefinition): UseStyleS; - (getCssStyleFn: GetStyleFn): UseStyleS; + (style: StyleDefinition): UseStyleHook; + (getCssStyleFn: GetStyleFn): UseStyleHook; } + /** * 业务应用中创建样式基础写法 */ export const createStyles: CreateStylesFn = - (styleOrGetStyleFn: StyleOrGetStyleFn) => + (styleOrGetStyleFn: StyleOrGetStyleFn) => (props?: P): ReturnStyles => { const theme = useTheme(); diff --git a/src/types/genericUtils.ts b/src/types/genericUtils.ts index 05710c9e..13b162d3 100644 --- a/src/types/genericUtils.ts +++ b/src/types/genericUtils.ts @@ -6,11 +6,17 @@ import { CSSObject } from '@emotion/css'; */ export type StyleDefinition = StyleObj extends string ? string - : Record; + : { + [Key in keyof StyleObj]: CSSObject | string; + }; /** * 根据用户返回的样式对象,返回一个可以给用户使用的 * 譬如用户输入为 { a: css`color: red;`, b: { color: 'red' } * 输出的类型泛型为 { a:string; b:string } */ -export type ReturnStyleToUse = T extends Record ? Record : string; +export type ReturnStyleToUse = T extends string + ? string + : { + [Key in keyof T]: string; + };