@inlang/paraglide-js
Version:
[](https://inlang.com)
33 lines (32 loc) • 990 B
JavaScript
export function jsDocBundleFunctionTypes(args) {
const localesUnion = args.locales.map((locale) => `"${locale}"`).join(" | ");
return `
* @param {${inputsType(args.inputs)}} inputs
* @param {{ locale?: ${localesUnion} }} options
* @returns {string}`;
}
/**
* Returns the types for the input variables.
*
* @example
* const inputs = [{ name: "age" }]
* inputsType(inputs)
* >> "{ age: NonNullable<unknown> }"
*/
export function inputsType(inputs) {
if (inputs.length === 0) {
return "{}";
}
// Deduplicate inputs by name to avoid TypeScript errors with duplicate properties in JSDoc
const uniqueInputMap = new Map();
for (const input of inputs) {
uniqueInputMap.set(input.name, input);
}
const uniqueInputs = Array.from(uniqueInputMap.values());
const inputParams = uniqueInputs
.map((input) => {
return `${input.name}: NonNullable<unknown>`;
})
.join(", ");
return `{ ${inputParams} }`;
}