From d318382d70de3537b1c05fa8a1333c7e44be683b Mon Sep 17 00:00:00 2001 From: arvinxx Date: Tue, 10 Jan 2023 13:55:50 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20fix:=20=E4=BF=AE=E6=AD=A3=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E5=AE=9A=E4=B9=89=E4=B8=8D=E5=87=86=E7=A1=AE=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/functions/createStyish.ts | 10 ++++++++-- src/functions/createStyles.ts | 9 +++++---- src/types/genericUtils.ts | 10 ++++++++-- 3 files changed, 21 insertions(+), 8 deletions(-) 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; + };