Skip to content

Commit bda650b

Browse files
committed
chore: replace result: unknown in generated appKitTypes.d.ts
The type generator falls back to `result: unknown` when no warehouse is available during template generation, causing TS build errors in AnalyticsPage.tsx. Add a postProcess step that replaces unknown results with correct types for known template queries. Co-authored-by: Isaac
1 parent ccb4c40 commit bda650b

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

tools/generate-app-templates.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ const DATABRICKS_CLI = process.env.DATABRICKS_CLI ?? "databricks";
3939
const APPKIT_SECTION_START = "<!-- appkit-start -->";
4040
const APPKIT_SECTION_END = "<!-- appkit-end -->";
4141

42+
/**
43+
* Known query result types for template SQL files.
44+
* The type generator cannot infer these without a warehouse connection,
45+
* so we hardcode them here to fix up `result: unknown` in appKitTypes.d.ts.
46+
*/
47+
const QUERY_RESULT_TYPES: Record<string, string> = {
48+
hello_world: "Array<{ value: string }>",
49+
mocked_sales:
50+
"Array<{ month: string; month_num: number; revenue: number; expenses: number; customers: number }>",
51+
};
52+
4253
interface AppTemplate {
4354
/** Output directory name and --name passed to databricks apps init */
4455
name: string;
@@ -191,6 +202,39 @@ function postProcess(appDir: string, app: AppTemplate): void {
191202
"host: https://your-workspace.cloud.databricks.com",
192203
);
193204
writeFileSync(databricksYmlPath, fixedYml);
205+
206+
// 4. Fix `result: unknown` in appKitTypes.d.ts — the type generator falls back
207+
// to `unknown` when no warehouse is available during template generation.
208+
fixAppKitTypes(appDir);
209+
}
210+
211+
/**
212+
* Replaces `result: unknown` entries in appKitTypes.d.ts with concrete types
213+
* from QUERY_RESULT_TYPES. Without a warehouse connection the type generator
214+
* cannot run DESCRIBE QUERY, so it falls back to `unknown`.
215+
*/
216+
function fixAppKitTypes(appDir: string): void {
217+
const typesPath = join(appDir, "client/src/appKitTypes.d.ts");
218+
if (!existsSync(typesPath)) return;
219+
220+
let content = readFileSync(typesPath, "utf-8");
221+
let replaced = false;
222+
223+
for (const [queryName, resultType] of Object.entries(QUERY_RESULT_TYPES)) {
224+
// Match the query block's `result: unknown` line, scoped to the query name
225+
const pattern = new RegExp(
226+
`(${queryName}:\\s*\\{[\\s\\S]*?)result:\\s*unknown;`,
227+
);
228+
if (pattern.test(content)) {
229+
content = content.replace(pattern, `$1result: ${resultType};`);
230+
replaced = true;
231+
}
232+
}
233+
234+
if (replaced) {
235+
writeFileSync(typesPath, content);
236+
console.log(` Fixed appKitTypes.d.ts result types`);
237+
}
194238
}
195239

196240
/**

0 commit comments

Comments
 (0)