refactor: TypeScript 6 with full strict mode - #377
Merged
Conversation
Bumps typescript 5.7 -> 6.0 and rewrites tsconfig for what the project actually is today: a Vite-bundled browser app typechecked with tsc --noEmit (target/lib es2022, moduleResolution bundler, strict, skipLibCheck for the ol/ol-ext type packages). The old config still declared jsx: react, an es6 lib (which made flatMap and Object.entries errors) and an outDir nobody used. The source fixes are mechanical and behavior-preserving: - definite-assignment assertions on GttClient properties (populated by the init helpers; the early return covers a missing target) - explicit this annotations on instance-bound functions - null guards and optional chaining for DOM lookups; the repeated issue-form label scan is extracted into a shared findFieldInput helper (it was copy-pasted five times across geocoding and helpers, typed in a way strict mode rejects) - getStyle now matches OpenLayers' StyleFunction signature - declarations for style side-effect imports; stale FontFaceSet augmentation from the icon-font era deleted Adds a pnpm typecheck script and runs it in CI before the build so the codebase stays strict-clean.
There was a problem hiding this comment.
Pull request overview
This PR upgrades the frontend toolchain to TypeScript 6 and enforces full strict: true typechecking in CI, with a tsconfig rewrite aligned to the current Vite/browser build and a set of strict-mode-driven source fixes across the GttClient OpenLayers/geocoding code.
Changes:
- Rewrites
tsconfig.jsonfor a Vite-bundled browser app (ES2022 libs, bundler resolution,strict: true,noEmit) and adds a CIpnpm typecheckgate. - Updates OpenLayers style/geolocation/edit/layer init code and geocoding/search utilities to satisfy strict mode (explicit
this, null guards, corrected signatures). - Adds/adjusts ambient type declarations for stylesheet side-effect imports and removes stale global font-related typings.
Reviewed changes
Copilot reviewed 14 out of 18 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tsconfig.json | Updates compiler settings for TS6 + strict typechecking with noEmit and browser/Vite-appropriate targets. |
| src/components/gtt-client/openlayers/styles.ts | Aligns style function typing with OpenLayers’ StyleFunction signature and adds null-safety. |
| src/components/gtt-client/openlayers/geolocation.ts | Uses undefined to clear geometries to satisfy stricter typings. |
| src/components/gtt-client/openlayers/edit.ts | Adds optional chaining for safer geometry access. |
| src/components/gtt-client/init/layers.ts | Makes initLayers return type reflect existing early-return behavior. |
| src/components/gtt-client/init/events.ts | Improves DOM query typing via generic querySelectorAll<T>(). |
| src/components/gtt-client/helpers/index.ts | Adds findFieldInput helper and refactors repeated label scans to use it. |
| src/components/gtt-client/GttClient.ts | Uses definite-assignment assertions and tweaks i18n parsing for strict mode compatibility. |
| src/components/gtt-client/geocoding/SearchGTT.ts | Adds definite-assignment assertion for a late-assigned button property. |
| src/components/gtt-client/geocoding/SearchGoogle.ts | Updates defaults and adds strict-mode this typing / non-null assertions. |
| src/components/gtt-client/geocoding/SearchFactory.ts | Fixes callback typing to match the actual callback payload shape. |
| src/components/gtt-client/geocoding/index.ts | Adds null guards/optional chaining and reuses findFieldInput in geocoding flows. |
| src/components/gtt-client/geocoding/CustomButtonMixin.ts | Works around missing typings on ol-ext element helper by casting. |
| src/@types/custom-fontface-set.d.ts | Removes stale global augmentation. |
| src/@types/assets.d.ts | Adds ambient module declarations for CSS/SCSS side-effect imports. |
| package.json | Bumps TypeScript to v6 and adds a typecheck script. |
| pnpm-lock.yaml | Locks TypeScript v6 resolution. |
| .github/workflows/test-postgis.yml | Enforces pnpm typecheck in CI before build. |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- guard the place-search submit handler against no radio selection - fail fast with an explicit error when the #gtt-defaults i18n payload is missing instead of parsing an empty fallback object that would crash later with a less actionable message
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.
Final piece of the Phase 2 frontend architecture series: the toolchain typechecks the whole bundle under
strict: trueon TypeScript 6, and CI enforces it.tsconfig rewrite
The old config described a project that no longer exists:
jsx: react, anes6lib (the source of the long-standingflatMap/Object.entrieserrors), an unusedoutDir, and apathsmapping from the webpack era. The new config matches reality, a Vite-bundled browser app typechecked withtsc --noEmit:target/libes2022,moduleResolution: bundlerstrict: trueskipLibCheck: true(the ol/ol-ext type packages do not pass a strict lib check themselves)tsc --noEmitwent from 16 errors (silently tolerated; nothing ran tsc) to 0, andpnpm typechecknow runs in CI before the build.Source fixes
All mechanical and behavior-preserving:
GttClientproperties, which are populated by the init helpers the constructor calls.thisannotations on the remaining instance-bound functions (geocoding, styles).findFieldInputhelper.getStylenow matches OpenLayers'StyleFunctionsignature instead of relying on an unsound parameter type.FontFaceSetaugmentation left over from the icon-font era is deleted.SearchGoogle's defaultapiKeyis''instead ofnull(same constructor-time rejection), andinitLayersdeclares theundefinedit could already return.Verification
pnpm typecheck: 0 errors;pnpm buildgreen.