Conversation
… locals Records today's import blocks and validate() output for five causes: - the ten-name validate bundle imported when one validator or none is called - a complex extension resolving to a flat-input profile still imports its sub-extension value type (CodeableConcept) - an extension slice without a url imports Extension and ensurePath unused - a generic extension imports its profile class unused - a profile with nothing to validate emits the profileName/res locals
- collectValidateBody collects the validate() expressions and the validate* helpers they call; the profile-helpers import takes its validate* names from that set, and validate() declares profileName/res only when it has an expression - every other helper is imported under the condition its emitter uses: ensureSliceDefaults, setArraySlice/getArraySlice, isExtension, getExtensionValue, pushExtension, ensurePath and extractComplexExtension; isRawExtensionInput and ensureProfile no longer depend on the canonical url - collectExtensionMethodInfos is the one list of url'd extensions the extension methods and the imports both read, so an extension without a url imports nothing - a complex extension resolving to a flat-input profile no longer imports its sub-extension value types; a generic extension no longer imports its profile class
Flips the pin to the intended import blocks and the local-free empty validate(), and updates the snapshots whose profile modules lose unused helper and type imports.
… its params generateType renders any schema named Reference, Coding or CodeableConcept with the hardcoded `<T extends string>` and drops its IR generic params, but generateDependenciesImports still imported the constraint type only those params named. The CDA Reference imported `Base` (r5) without using it.
Every example tsconfig extends the root one, so an unused import in generated output now fails the example typecheck. Drops the unused test fixtures it flags (_dateTimeType, _periodType, _rangeType, _basePackageInfo) and writes the vflat member check in _flatContractTypes as an expression.
- examples/typescript-r4-us-core/fhir-types: 17 profile modules - examples/typescript-custom-packages/__snapshots__: profile-complex-extension-flat, profile-typed-bundle - examples/on-the-fly/norge-r4/__snapshots__: kjernejournal-profiles - examples/on-the-fly/ccda/__snapshots__: uv-extensions-r4
Palid
marked this pull request as draft
October 1, 2026 01:21
This was referenced Oct 1, 2026
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.
Profile modules imported fixed bundles of helpers and types, picked by coarse structural conditions (any field, any slice, any extension with a url) before the class body was written. Now the
validate()body is collected first, and every import is derived from what the module actually emits.Closes #254
Profile imports
collectValidateBodyreturns thevalidate()error and warning expressions plus the names of thevalidate*helpers they call; theprofile-helpersimport takes its validators from that setvalidate()declaresprofileNameandresonly when it has an expression to emitsetArraySlice/getArraySliceonly for a bounded array slice,setArraySliceAll/getArraySliceAllonly for an unbounded one (isUnboundedSlice, now shared with the slice setters and getters),ensureSliceDefaultsonly with slice auto-fieldscollectExtensionMethodInfos, the same list the extension methods are generated from:isExtensiononly where an emitted branch checks it (extensionProfileHasFlatInputfor complex extensions),getExtensionValueonly for single-value extensions,pushExtensiononly for repeating onesisRawExtensionInputandensureProfileno longer check for a canonical url…ProfileFlattype only for complex onestest/api/write-generator/profile-unused-imports.test.tspins each caseThe validate bundle was imported whole whenever a profile had a field;
birthPlacecalls four of the ten:import { applyFixedValue, validateRequired, - validateExcluded, validateFixedValue, - validateSliceCardinality, - validateSliceFields, - validateEnum, - validateReference, validateChoiceRequired, validateChoiceProhibited, - validateMustSupport, } from "../../profile-helpers";A profile with nothing to validate still declared the two locals the expressions read (
NotedPatient):validate(): { errors: string[]; warnings: string[] } { - const profileName = "NotedPatient" - const res = this.resource return { errors: [], warnings: [],noUnusedLocals
tsconfig.jsonturns it on; every example tsconfig extends the root one, so the example typechecks in CI now fail on an unused import or local in generated output (the committed us-core output had 97TS6133before this branch, 0 now)_dateTimeType,_periodType,_rangeType,_basePackageInfo, and_validNote(nowvoid vFlat!.note.trim())@ts-expect-erroroverconst _note: string = flat!.notewould have been satisfied byTS6133alone, so it is now the expressionvoid flat!.note.trim()CDA Reference import
generateTyperendersReference,CodingandCodeableConceptwith the hardcoded<T extends string = string>and drops their IR generic params, butgenerateDependenciesImportsstill imported the constraint types of those paramsdroppedGenericConstraintUrls)hl7-cda-uv-core/Reference.tsin the ccda output:-import type { Base } from "../hl7-fhir-r5-core/Base"; import type { BL } from "../hl7-cda-uv-core/BL"; import type { ExternalAct } from "../hl7-cda-uv-core/ExternalAct";Reach
examples/typescript-r4-us-core: the 17 committed profile modules, import removals onlytest/api/write-generator/TS6133/TS6192/TS6196