@spark-web/utils
Version:
--- title: Utilities isExperimentalPackage: true ---
42 lines (36 loc) • 1.42 kB
JavaScript
Object.defineProperty(exports, '__esModule', { value: true });
var react = require('react');
var typeCheck = require('../../dist/type-check-042a577c.cjs.dev.js');
/**
* This is a hack for sure. The thing is, getting a component to intelligently
* infer props based on a component or JSX string passed into an `as` prop is
* kind of a huge pain. Getting it to work and satisfy the constraints of
* `forwardRef` seems dang near impossible. To avoid needing to do this awkward
* type song-and-dance every time we want to forward a ref into a component
* that accepts an `as` prop, we abstract all of that mess to this function for
* the time time being.
*/
var forwardRefWithAs = function forwardRefWithAs(render) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return /*#__PURE__*/react.forwardRef(render);
};
/**
* An alternative to `Object.keys()` that avoids type widening.
*
* @param {object} value Object containing keys to extract
*
* @example
* Object.keys({ foo: 1, bar: 2 }) // string[]
* typedKeys({ foo: 1, bar: 2 }) // ("foo" | "bar")[]
*/
function typedKeys(value) {
return Object.keys(value);
}
exports.isBoolean = typeCheck.isBoolean;
exports.isFunction = typeCheck.isFunction;
exports.isNumber = typeCheck.isNumber;
exports.isString = typeCheck.isString;
exports.forwardRefWithAs = forwardRefWithAs;
exports.typedKeys = typedKeys;
;