Skip to content

feat: add --prefer-unknown option for TypeScript and Flow#2862

Merged
schani merged 4 commits into
glideapps:masterfrom
k-vasily:feat/prefer-unknown
Jul 20, 2026
Merged

feat: add --prefer-unknown option for TypeScript and Flow#2862
schani merged 4 commits into
glideapps:masterfrom
k-vasily:feat/prefer-unknown

Conversation

@k-vasily

@k-vasily k-vasily commented Mar 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds a --prefer-unknown CLI flag that emits unknown instead of any in TypeScript output, and mixed instead of any in Flow output
  • Introduces an abstract anyType() method in TypeScriptFlowBaseRenderer to centralize the any/unknown type selection
  • Adds test coverage via quickTestRendererOptions

This is a fresh implementation of the feature proposed in #2194 by @RichiCoder1, adapted to the current codebase where TypeScriptFlow has been split into multiple files. Closes #1619.

Thanks to @RichiCoder1 for the original PR, and to @dvdsgl and @SBrandeis for their involvement.

Test plan

  • tsc --noEmit passes
  • echo '{"name": "test"}' | quicktype -l ts --prefer-unknown outputs unknown instead of any
  • Default output (without flag) unchanged
  • CI tests pass

🤖 Generated with Claude Code

Add a `--prefer-unknown` CLI flag that emits `unknown` instead of `any`
in TypeScript output, and `mixed` instead of `any` in Flow output.

This is a fresh implementation of the feature proposed in PR glideapps#2194 by
@RichiCoder1, adapted to the current codebase structure where
TypeScriptFlow was split into multiple files.

Closes glideapps#1619
schani and others added 3 commits July 9, 2026 15:47
Resolves the ESM/spread-syntax conflicts in the TypeScriptFlow language
files and reworks the option so that only the public API surface (type
declarations and converter signatures) switches to unknown/mixed, while
the deliberately dynamic runtime-typecheck helpers stay on `any` --
with the PR's original substitution the generated code no longer
compiled when runtime typechecks were enabled.

With `raw-type any` and no runtime typecheck the deserializer now
narrows its unknown/mixed parameter with an explicit cast.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The next release is a major, so the breaking output change is
sanctioned: generated type declarations and converter signatures now
use unknown (TypeScript) / mixed (Flow) instead of any by default,
which also makes the standard typescript/flow fixtures exercise the
new output across the whole corpus.  Opt out with --no-prefer-unknown
(CLI) or "prefer-unknown": false; the quick-test entries pin the
legacy any output for both fixtures.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@schani
schani merged commit d5096b5 into glideapps:master Jul 20, 2026
25 checks passed
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.

add flag for typescript to use unknown instead of any

2 participants