Skip to content

Commit 10d7efb

Browse files
author
Sushil Khairnar
committed
fix: resolve TypeScript ESLint unsafe member access errors in PGliteInstanceManager
- Add proper type guards for PgParseResult to handle error and success cases - Replace unsafe member access with type-safe checks using isParseError/isParseSuccess - Isolate type assertions to dedicated helper functions - Add fallback handling for edge cases where neither error nor parse_tree exist Fixes unsafe member access violations on parseResult.error and parseResult.parse_tree
1 parent f0b8dd1 commit 10d7efb

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

frontend/internal-packages/pglite-server/src/PGliteInstanceManager.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,35 @@ export class PGliteInstanceManager {
6262
* Execute SQL statements and return results with metadata
6363
* Uses PostgreSQL parser to properly handle complex statements including dollar-quoted strings
6464
*/
65+
private isParseError(
66+
result: PgParseResult,
67+
): result is { error: { message: string } } {
68+
return (result as any).error !== null
69+
}
70+
71+
private isParseSuccess(
72+
result: PgParseResult,
73+
): result is { parse_tree: { stmts: any[] } } {
74+
return (result as any).parse_tree?.stmts != null
75+
}
76+
6577
private async executeSql(sqlText: string, db: PGlite): Promise<SqlResult[]> {
6678
try {
6779
const parseResult: PgParseResult = await pgParse(sqlText)
6880

69-
if (parseResult.error) {
81+
if (this.isParseError(parseResult)) {
7082
return [this.createParseErrorResult(sqlText, parseResult.error.message)]
7183
}
7284

73-
const statements = this.extractStatements(
74-
sqlText,
75-
parseResult.parse_tree.stmts,
76-
)
77-
return await this.executeStatements(statements, db)
85+
if (this.isParseSuccess(parseResult)) {
86+
const statements = this.extractStatements(
87+
sqlText,
88+
parseResult.parse_tree.stmts,
89+
)
90+
return await this.executeStatements(statements, db)
91+
}
92+
93+
return [this.createParseErrorResult(sqlText, 'No statements found')]
7894
} catch (error) {
7995
return await this.executeFallback(sqlText, db, error)
8096
}

0 commit comments

Comments
 (0)