Skip to content

Commit 4356a8e

Browse files
authored
chore: chore: improve TS type (#483)
* chore: improve type * chore: update description
1 parent 333d190 commit 4356a8e

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/composeProps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function composeProps<T extends Record<string, any>>(
1717
};
1818
}
1919
});
20-
return composedProps;
20+
return composedProps as T;
2121
}
2222

2323
export default composeProps;

src/warning.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,18 @@ export const preMessage = (fn: preMessageFn) => {
1616
preWarningFns.push(fn);
1717
};
1818

19+
/**
20+
* Warning if condition not match.
21+
* @param valid Condition
22+
* @param message Warning message
23+
* @example
24+
* ```js
25+
* warning(false, 'some error'); // print some error
26+
* warning(true, 'some error'); // print nothing
27+
* warning(1 === 2, 'some error'); // print some error
28+
* ```
29+
*/
1930
export function warning(valid: boolean, message: string) {
20-
// Support uglify
2131
if (
2232
process.env.NODE_ENV !== 'production' &&
2333
!valid &&
@@ -34,8 +44,8 @@ export function warning(valid: boolean, message: string) {
3444
}
3545
}
3646

47+
/** @see Similar to {@link warning} */
3748
export function note(valid: boolean, message: string) {
38-
// Support uglify
3949
if (
4050
process.env.NODE_ENV !== 'production' &&
4151
!valid &&
@@ -67,10 +77,12 @@ export function call(
6777
}
6878
}
6979

80+
/** @see Same as {@link warning}, but only warn once for the same message */
7081
export function warningOnce(valid: boolean, message: string) {
7182
call(warning, valid, message);
7283
}
7384

85+
/** @see Same as {@link warning}, but only warn once for the same message */
7486
export function noteOnce(valid: boolean, message: string) {
7587
call(note, valid, message);
7688
}
@@ -80,4 +92,3 @@ warningOnce.resetWarned = resetWarned;
8092
warningOnce.noteOnce = noteOnce;
8193

8294
export default warningOnce;
83-
/* eslint-enable */

0 commit comments

Comments
 (0)