Skip to content

PR-244: replace any unknown#264

Open
JasonShin wants to merge 5 commits intomainfrom
pr-244-replace-any-unknown
Open

PR-244: replace any unknown#264
JasonShin wants to merge 5 commits intomainfrom
pr-244-replace-any-unknown

Conversation

@JasonShin
Copy link
Owner

Continuing on #244...

rebasing with main branch

Leo5878 added 4 commits March 10, 2026 22:35
# Conflicts:
#	src/ts_generator/sql_parser/expressions/translate_expr.rs
Copilot AI review requested due to automatic review settings March 10, 2026 11:37
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR continues the effort from #244 to prefer unknown over any in generated TypeScript types, updating the Rust type-mapping logic and refreshing the demo/test fixtures and snapshots to match.

Changes:

  • Introduces TsFieldType::Unknown and switches several “fallback”/untyped mappings from any to unknown.
  • Updates SQL expression and data type translation paths to emit unknown in more cases.
  • Regenerates/updates demo query outputs and snapshots to reflect unknown types and renamed query artifacts.

Reviewed changes

Copilot reviewed 26 out of 26 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/demo_json/postgres/array_operations.ts Updates demo query name for array literal case; now intended to reflect unknown.
tests/demo_json/postgres/array_operations.snapshot.ts Updates generated snapshot types from any to unknown and renames ArrayLiteral* types.
tests/demo_json/postgres/array_operations.queries.ts Updates generated query types from any to unknown and renames ArrayLiteral* types.
tests/demo/typescript/expression/types.ts Updates demo TypeScript types to use unknown instead of any.
tests/demo/typescript/expression/as_const.ts Changes Record<string, any> to Record<string, unknown> in a demo fixture.
tests/demo/select/select.snapshot.ts Updates snapshot field type(s) from any to unknown.
tests/demo/select/select.queries.ts Updates query field type(s) from any to unknown.
tests/demo/select/no-default-table.snapshot.ts Updates multiple JSON-ish snapshot fields from any to unknown.
tests/demo/select/no-default-table.queries.ts Updates multiple JSON-ish query fields from any to unknown.
tests/demo/datetime_functions/time_functions.snapshot.ts Updates snapshot time/interval-related fields from any to unknown.
tests/demo/datetime_functions/time_functions.queries.ts Updates query time/interval-related fields from any to unknown.
tests/demo/datetime_functions/date_functions.snapshot.ts Updates snapshot date arithmetic field from any to unknown.
tests/demo/datetime_functions/date_functions.queries.ts Updates query date arithmetic field from any to unknown.
tests/demo/case_expressions/simple_case.snapshot.ts Updates CASE expression snapshot outputs from any to unknown.
tests/demo/case_expressions/simple_case.queries.ts Updates CASE expression query outputs from any to unknown.
tests/demo/case_expressions/searched_case.snapshot.ts Updates searched CASE snapshot outputs from any to unknown.
tests/demo/case_expressions/searched_case.queries.ts Updates searched CASE query outputs from any to unknown.
tests/demo/case_expressions/nested_case.snapshot.ts Updates nested CASE snapshot outputs from any to unknown.
tests/demo/case_expressions/nested_case.queries.ts Updates nested CASE query outputs from any to unknown.
tests/demo/case_expressions/case_in_clauses.snapshot.ts Updates CASE-in-clause snapshot output from any to unknown.
tests/demo/case_expressions/case_in_clauses.queries.ts Updates CASE-in-clause query output from any to unknown.
tests/demo/aggregate_functions/basic_aggregates.snapshot.ts Updates aggregate snapshot outputs from any to unknown.
tests/demo/aggregate_functions/basic_aggregates.queries.ts Updates aggregate query outputs from any to unknown.
src/ts_generator/types/ts_query.rs Adds Unknown variant and shifts multiple default mappings from Any to Unknown.
src/ts_generator/sql_parser/expressions/translate_expr.rs Replaces multiple expression-result fallbacks from Any to Unknown.
src/ts_generator/sql_parser/expressions/translate_data_type.rs Switches several data type translations from Any to Unknown.
Comments suppressed due to low confidence (1)

src/ts_generator/types/ts_query.rs:123

  • TsFieldType::Unknown is added and most default/fallback mappings in this file now return Unknown, but from_sqlparser_datatype() (later in this file) still defaults to Any (including DataType::Array(_) => Self::Any and the final wildcard arm). If the goal is to eliminate any for unknown/unhandled types, consider aligning those fallbacks to Unknown as well so alias column definitions don’t reintroduce any into generated types.
  Any,
  Unknown,
  #[allow(dead_code)]
  Array2D(Array2DContent),
  Array(Box<TsFieldType>),
  #[allow(dead_code)]

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

const arrayLiteralAny = sql`
-- @name: array literal any
// Array literal and unknown
const arrayLiteralunknown = sql`
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arrayLiteralunknown uses inconsistent casing (likely a typo) compared to other camelCase identifiers in this fixture (e.g., arrayAggWithOrderBy, arrayWithParams). Renaming to arrayLiteralUnknown would keep naming consistent and easier to grep alongside the -- @name: array literal unknown annotation.

Suggested change
const arrayLiteralunknown = sql`
const arrayLiteralUnknown = sql`

Copilot uses AI. Check for mistakes.
let name: any = 'test'
let companyName = <string>name
let name: unknown = 'test'
let compunknownName = <string>name
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compunknownName looks like an unintended rename/typo (it reads like companyName with unknown inserted). Consider renaming it to a clearer identifier (e.g., companyName or compUnknownName) to avoid confusion in this TypeScript expression fixture.

Suggested change
let compunknownName = <string>name
let compUnknownName = <string>name

Copilot uses AI. Check for mistakes.
Comment on lines 487 to 490
Expr::JsonAccess { value: _, path: _ } => {
ts_query.insert_result(alias, &[TsFieldType::Any], is_selection, false, expr_for_logging)?;
ts_query.insert_param(&TsFieldType::Any, &false, &None)
ts_query.insert_result(alias, &[TsFieldType::Unknown], is_selection, false, expr_for_logging)?;
ts_query.insert_param(&TsFieldType::Unknown, &false, &None)
}
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR replaces many Any fallbacks with Unknown, but Expr::Value still falls back to TsFieldType::Any when it can’t infer a literal’s type (see the inferred_type assignment just above this hunk). If the intent is to avoid emitting any for unknown types, consider switching that fallback to TsFieldType::Unknown as well (keeping the Boolean special-case if needed).

Copilot uses AI. Check for mistakes.
Comment on lines 681 to +691
let args = match &func_obj.args {
FunctionArguments::List(arg_list) => &arg_list.args,
_ => {
// If no arguments or subquery, return Any
return ts_query.insert_result(Some(alias), &[TsFieldType::Any], is_selection, false, expr_for_logging);
return ts_query.insert_result(
Some(alias),
&[TsFieldType::Unknown],
is_selection,
false,
expr_for_logging,
);
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this file, the fallback for is_json_agg_function when there are no arguments/subquery was updated to Unknown, but the analogous fallback for is_json_build_function (just above) still returns TsFieldType::Any. To consistently avoid emitting any for unknown function return types, consider switching the json-build fallback to Unknown as well.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants