Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: chore: improve TS type #483

Merged
merged 2 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/composeProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function composeProps<T extends Record<string, any>>(
};
}
});
return composedProps;
return composedProps as T;
}

export default composeProps;
17 changes: 14 additions & 3 deletions src/warning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,18 @@ export const preMessage = (fn: preMessageFn) => {
preWarningFns.push(fn);
};

/**
* Warning if condition not match.
* @param valid Condition
* @param message Warning message
* @example
* ```js
* warning(false, 'some error'); // print some error
* warning(true, 'some error'); // print nothing
* warning(1 === 2, 'some error'); // print some error
* ```
*/
export function warning(valid: boolean, message: string) {
// Support uglify
if (
process.env.NODE_ENV !== 'production' &&
!valid &&
Expand All @@ -34,8 +44,8 @@ export function warning(valid: boolean, message: string) {
}
}

/** @see Similar to {@link warning} */
export function note(valid: boolean, message: string) {
// Support uglify
if (
process.env.NODE_ENV !== 'production' &&
!valid &&
Expand Down Expand Up @@ -67,10 +77,12 @@ export function call(
}
}

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

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

export default warningOnce;
/* eslint-enable */
Loading