Skip to content

Commit

Permalink
fix: error generic types on methofd (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
DeVoresyah authored Feb 29, 2024
1 parent 57467bf commit ac6c856
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
4 changes: 1 addition & 3 deletions src/core/hoc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ export const withStyles =

const colors = useMemo(
() =>
<T extends string | string[]>(
...args: (string | boolean | undefined)[]
): T => {
<T,>(...args: (string | boolean | undefined)[]): T => {
if (args.length === 1) {
return colorHelper(args[0] as string)(themeContext) as T;
} else if (args.length === 2) {
Expand Down
5 changes: 3 additions & 2 deletions src/core/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,21 @@ export const useStyles = (): ApplyInstance => {

const colors = useMemo(
() =>
<T extends string | string[]>(...args: (string | boolean | undefined)[]): T => {
<T,>(...args: (string | boolean | undefined)[]): T => {
if (args.length === 1) {
return colorHelper(args[0] as string)(themeContext) as T;
} else if (args.length === 2) {
return args.map((syntax) =>
colorHelper(syntax as string)(themeContext)
) as T;
) as unknown as T;
} else {
throw Error("Invalid color syntax");
}
},
[themeContext]
);


return {
apply,
colors,
Expand Down
2 changes: 1 addition & 1 deletion src/types/osmi.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface ApplyInstance {
apply: <T extends NamedStyles<T> | NamedStyles<any>>(
...args: (string | boolean | undefined)[]
) => any;
colors: (...args: (string | boolean | undefined)[]) => string | string[];
colors: <T,>(...args: (string | boolean | undefined)[]) => T;
switchTheme: (newMode: keyof typeof ThemeMode) => void;
scaleWidth: (width: number) => number;
scaleHeight: (height: number) => number;
Expand Down

0 comments on commit ac6c856

Please sign in to comment.