Add helper function to export ts functions to html

This commit is contained in:
2024-10-13 01:53:23 +02:00
committed by Bartuccio Antoine
parent 3b1d06a71d
commit b6e1c3bc88
2 changed files with 225 additions and 215 deletions

View File

@ -4,3 +4,17 @@ declare global {
const Alpine: AlpineType;
const gettext: (text: string) => string;
}
/**
* Helper function to export typescript functions to regular html and jinja files
* Without it, you either have to use the any keyword and suppress warnings or do a
* very painful type conversion workaround which is only here to please the linter
*
* This is only useful if you're using typescript, this is equivalent to doing
* window.yourFunction = yourFunction
**/
// biome-ignore lint/suspicious/noExplicitAny: Avoid strange tricks to export functions
export function exportToHtml(name: string, func: any) {
// biome-ignore lint/suspicious/noExplicitAny: Avoid strange tricks to export functions
(window as any)[name] = func;
}