From d3d3f1785a8a4c59a16fe8ad4cebb1840c2b4ce5 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Tue, 13 Aug 2024 11:05:56 +0200 Subject: [PATCH] fix(apps): type hints for results are automatically widened --- frontend/src/lib/components/apps/utils.ts | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/frontend/src/lib/components/apps/utils.ts b/frontend/src/lib/components/apps/utils.ts index 76cb92ec01..d2c0f53b38 100644 --- a/frontend/src/lib/components/apps/utils.ts +++ b/frontend/src/lib/components/apps/utils.ts @@ -174,15 +174,29 @@ export function buildExtraLib( .filter(([k, v]) => k != idToExclude && k != 'state') .map(([k, v]) => [k, Object.fromEntries(Object.entries(v).map(([k, v]) => [k, v.peak()]))]) .map( - ([k, v]) => `declare const ${k}: ${JSON.stringify(v)}; + ([k, v]) => `declare const ${k}: Widen<${JSON.stringify(v)}>; ` ) .join('\n') - return `${cs} + return ` + +type Widen = T extends string + ? string + : T extends number + ? number + : T extends boolean + ? boolean + : T extends Array + ? Array> + : T extends object + ? { [K in keyof T]: Widen } + : T; /** The mutable state of the app */ -declare const state: ${JSON.stringify(state)} & {[key: string]: any}; +declare const state: Widen<${JSON.stringify(state)}> & {[key: string]: any}; + +${cs} ${ goto