fix(typescript): annotate m() helper's props array to satisfy noImplicitAny#2977
Merged
Conversation
…citAny (#2430) Co-Authored-By: gpt-5.6-sol via pi <noreply@openai.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.
Bug
The shared JavaScript/TypeScript/Flow runtime-typecheck helper
m()(used whenever the generated model contains a map/dictionary-typed object, i.e. an object with arbitrary/unknown keys all sharing one value type) emitted an untyped array literal:Compiling TypeScript output with
--noImplicitAny(andstrictNullChecks: false, which is TypeScript's default) fails with:Root cause
packages/quicktype-core/src/language/JavaScript/JavaScriptRenderer.tsemits both ano()helper (typed object with a known property list) and anm()helper (map type).o()'spropsparameter is typed via the renderer's existing conditional type-annotation mechanism (this.typeAnnotations, which resolves to": any[]"in TS/Flow mode and""in plain JS mode).m()'s inline[]literal never went through that mechanism, so undernoImplicitAnyTypeScript couldn't widen it pastnever[].Fix
Reuse the same
anyArrayAnnotationmechanismo()already uses, by declaringpropsas a local variable instead of an inline literal:This is valid TypeScript, valid Flow (since
anyArrayAnnotationis""there... actually Flow gets": any[]"too and this syntax is valid Flow), and plain JavaScript output is untouched (anyArrayAnnotationis""there, so it staysconst props = [];).Test coverage
test/fixtures/typescript/tsconfig.jsonnow sets"noImplicitAny": trueand"strictNullChecks": false, matching the exact compiler flags from the bug report, so thetypescriptfixture'stsc -p .compile step actually exercises this check (previously TypeScript's defaultnoImplicitAny: falsesilently masked the bug for every existing sample).test/inputs/json/priority/number-map.jsonalready exercises them()helper (an object with arbitrary punctuation-heavy keys, inferred as a map) and is part of thetypescriptfixture's always-run priority set, so no new input file was needed.Verification
QUICKTEST=true FIXTURE=typescript script/test test/inputs/json/priority/number-map.json→ failed withTS7018viatsc -p ..QUICKTEST=true FIXTURE=typescript script/test(78 tests) → all pass.QUICKTEST=true FIXTURE=javascript script/test test/inputs/json/priority/number-map.json→ passes (plain JS output unaffected).--lang flow) for the same sample and confirmed the emittedm()helper is valid Flow syntax.quicktype -s json sample.json -o out.tsthentsc --noImplicitAny --strictNullChecks false --noEmit out.ts) before and after the fix — TS7018 before, clean compile after.npm run buildpasses.Fixes #2430
🤖 Generated with Claude Code