feat: add --prefer-unknown option for TypeScript and Flow#2862
Merged
Conversation
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
k-vasily
force-pushed
the
feat/prefer-unknown
branch
from
March 11, 2026 16:53
acba960 to
bf6b307
Compare
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
--prefer-unknownCLI flag that emitsunknowninstead ofanyin TypeScript output, andmixedinstead ofanyin Flow outputanyType()method inTypeScriptFlowBaseRendererto centralize the any/unknown type selectionquickTestRendererOptionsThis 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 --noEmitpassesecho '{"name": "test"}' | quicktype -l ts --prefer-unknownoutputsunknowninstead ofany🤖 Generated with Claude Code