@builder.io/mitosis
Version:
Write components once, run everywhere. Compiles to Vue, React, Solid, and Liquid. Import code from Figma and Builder.io
21 lines (20 loc) • 714 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.getTypedFunction = void 0;
/**
* Get functions with typescript typing
*/
const getTypedFunction = (code, typescript, typeParameter) => {
if (!typeParameter || !typescript) {
return code;
}
const firstParenthesisIndex = code.indexOf('{');
// The function should have at least one {
if (firstParenthesisIndex < 0) {
return code;
}
const preType = code.slice(0, firstParenthesisIndex - 1);
const postType = code.slice(firstParenthesisIndex, code.length);
return [preType, ': ', `ReturnType<${typeParameter}>`, postType].join('');
};
exports.getTypedFunction = getTypedFunction;
;