From 6111e2f27ca39bdbe1cc1852dbf287ea7bf1b57c Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Mon, 9 Jan 2023 02:31:21 +0900 Subject: [PATCH] Cleanup types --- packages/yoshiki/src/native/type.ts | 10 +++------- packages/yoshiki/src/shorthands.ts | 27 +++++++++++---------------- packages/yoshiki/src/type.ts | 24 ------------------------ packages/yoshiki/src/web/generator.ts | 3 ++- 4 files changed, 16 insertions(+), 48 deletions(-) diff --git a/packages/yoshiki/src/native/type.ts b/packages/yoshiki/src/native/type.ts index a59780b..514ef9f 100644 --- a/packages/yoshiki/src/native/type.ts +++ b/packages/yoshiki/src/native/type.ts @@ -3,11 +3,11 @@ // Licensed under the MIT license. See LICENSE file in the project root for details. // -import { FilterOr, WithState, YoshikiStyle, Length, StyleList } from "../type"; +import { WithState, YoshikiStyle, StyleList } from "../type"; import { shorthandsFn } from "../shorthands"; import { ImageStyle, StyleProp, TextStyle, ViewStyle } from "react-native"; import { Theme } from "../theme"; -import { forceBreakpoint, WithBreakpoints } from "../utils"; +import { forceBreakpoint } from "../utils"; // The extends any check is only used to make EnhancedStyle a distributive type. // This means EnhancedStyle = EnhancedStyle | EnhancedStyle @@ -15,11 +15,7 @@ export type EnhancedStyle = Properties extends any ? { [key in keyof Properties]: YoshikiStyle; } & { - [key in keyof typeof shorthandsFn]?: FilterOr< - Parameters[0], - Length, - YoshikiStyle - >; + [key in keyof typeof shorthandsFn]?: Parameters[0]; } : never; diff --git a/packages/yoshiki/src/shorthands.ts b/packages/yoshiki/src/shorthands.ts index 01b9d63..285c724 100644 --- a/packages/yoshiki/src/shorthands.ts +++ b/packages/yoshiki/src/shorthands.ts @@ -3,51 +3,46 @@ // Licensed under the MIT license. See LICENSE file in the project root for details. // -import type { CommonStyle } from "./type"; -import type { ViewStyle } from "react-native"; - -type YSPs = CommonStyle; - export const shorthandsFn = { - p: (v: YSPs["padding"]): YSPs => ({ + p: (v: string | number) => ({ padding: v, }), - pX: (v: YSPs["paddingLeft"]): YSPs => ({ + pX: (v: string | number) => ({ paddingLeft: v, paddingRight: v, }), - paddingX: (v: YSPs["paddingLeft"]): YSPs => ({ + paddingX: (v: string | number) => ({ paddingLeft: v, paddingRight: v, }), - pY: (v: YSPs["paddingTop"]): YSPs => ({ + pY: (v: string | number) => ({ paddingTop: v, paddingBottom: v, }), - paddingY: (v: YSPs["paddingTop"]): YSPs => ({ + paddingY: (v: string | number) => ({ paddingTop: v, paddingBottom: v, }), - m: (v: YSPs["margin"]): YSPs => ({ + m: (v: string | number) => ({ margin: v, }), - mX: (v: YSPs["marginLeft"]): YSPs => ({ + mX: (v: string | number) => ({ marginLeft: v, marginRight: v, }), - marginX: (v: YSPs["marginLeft"]): YSPs => ({ + marginX: (v: string | number) => ({ marginLeft: v, marginRight: v, }), - mY: (v: YSPs["marginTop"]): YSPs => ({ + mY: (v: string | number) => ({ marginTop: v, marginBottom: v, }), - marginY: (v: YSPs["marginTop"]): YSPs => ({ + marginY: (v: string | number) => ({ marginTop: v, marginBottom: v, }), - bg: (v: YSPs["backgroundColor"]): YSPs => ({ + bg: (v: string) => ({ backgroundColor: v, }), }; diff --git a/packages/yoshiki/src/type.ts b/packages/yoshiki/src/type.ts index 7f9e23d..b12c94e 100644 --- a/packages/yoshiki/src/type.ts +++ b/packages/yoshiki/src/type.ts @@ -4,8 +4,6 @@ // import { breakpoints, Theme } from "./theme"; -import { Properties as _CssProperties } from "csstype"; -import { shorthandsFn } from "./shorthands"; export type YoshikiStyle = | Property @@ -35,25 +33,3 @@ export const processStyleList =