Skip to content

Commit 1753fe8

Browse files
author
Mohit
committed
ts changes
1 parent 58e5be5 commit 1753fe8

3 files changed

Lines changed: 7 additions & 8 deletions

File tree

lib/Sugar.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,16 +147,18 @@ export default class Sugar<T> {
147147

148148
create<P extends NamedStyles<P> | NamedStyles<any>>(
149149
objFn: Fn<T, P> | P
150-
): StyleSheetType<P> {
150+
): P extends NamedStyles<P> ? StyleSheetType<P> : P {
151151
if (typeof objFn === 'function') {
152152
const sheet = new Sheet(objFn);
153153
this.sheets.push(sheet);
154154
if (this.builded) {
155155
sheet.calc(this.theme, this.constants, this.activeIndex);
156156
}
157-
return sheet.getResult() as StyleSheetType<P>;
157+
return sheet.getResult() as P extends NamedStyles<P>
158+
? StyleSheetType<P>
159+
: P;
158160
}
159-
return objFn as StyleSheetType<P>;
161+
return objFn as P extends NamedStyles<P> ? StyleSheetType<P> : P;
160162
}
161163

162164
_calculateActiveIndex(): void {

lib/type.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ export type NamedStyles<T> = {
2121

2222
export type S = NamedStyles<any>;
2323

24-
export type Fn<T, P> = (
25-
theme: T,
26-
constants: ConstantsType
27-
) => P extends NamedStyles<P> ? NamedStyles<P> : P;
24+
export type Fn<T, P> = (theme: T, constants: ConstantsType) => P;
2825

2926
export type StyleSheetType<P> = {
3027
[K in keyof P]: {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-sugar-style",
3-
"version": "0.1.7",
3+
"version": "0.1.8",
44
"description": "React Native Stylesheet alternative with theme support",
55
"author": "mohit23x",
66
"license": "MIT",

0 commit comments

Comments
 (0)