Skip to content

refactor(*): enable TypeScript strict mode - #1852

Open
ivanvpetrov wants to merge 4 commits into
ipetrov/igx-templates-coveragefrom
ipetrov/ts-strict-mode
Open

ivanvpetrov wants to merge 4 commits into
ipetrov/igx-templates-coveragefrom
ipetrov/ts-strict-mode

Conversation

@ivanvpetrov

@ivanvpetrov ivanvpetrov commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1613

Description

Enables "strict": true and fixes every compiler error it raised (697 across core, cli, igx-templates, ng-schematics, scripts and the specs).

Config

  • strict: true is set in tsconfig.json, tsconfig-pack.json and packages/ng-schematics/tsconfig.json. The ng-schematics config previously enabled only noImplicitAny, noImplicitThis and strictNullChecks.
  • New dev dependencies:
    • @types/through2@^2.0.41 in core
    • @types/resolve@^1.20.6 in cli
    • yarn.lock only adds these two packages. Neither appears in the emitted declarations, so they stay dev-only.
    • After pulling, run yarn install; without it the build fails with TS7016 for resolve and through2.

How errors were fixed

  • Type-only changes wherever possible.
    • ! is used for properties assigned after construction (template metadata, prompt-session state, schematic options) and for values that can't be missing at runtime (for example, a name the user just picked from a list built from the same source).
    • catch variables are narrowed with as Error.
  • Lookups now return honest types.
    • getTemplateById, getTemplateByName, getComponentByName, getFrameworkById, getFrameworkByName and getProjectLibraryByName return T | undefined.
    • getProject returns ProjectTemplate | null.
    • getProjectLibrary returns ProjectLibrary | null | undefined, which matches what it returned before.
    • Callers that already checked the result needed no change; the others assert, keep their existing guard, or (for upgrade) gained one. See below.
  • Specs only gained type annotations, ! and casts. No existing assertion or test input changed.

Public type changes (@igniteui/cli-core declarations)

TypeScript consumers that compile with strictNullChecks may need to handle the new undefined / null results. Worth a line in the release notes when the next version is cut.

  • Lookup return types, as listed above.
  • ProjectLibrary interface: the matching lookup signatures.
  • BaseTemplate.setExtraConfiguration: now takes { [key: string]: unknown } and returns void.
  • Template.registerInProject: now returns void.
  • ProjectConfig.validateProperty: now returns { message?: string, valid: boolean, value?: any }.
  • ChangeRequest.node and TypeScriptAstTransformer.formatter are now optional.
  • defaultDelimiters is now Required<TemplateDelimiters>.

Changes that touch runtime code. Each one either gives the same result as before or replaces a code path that would have crashed:

  • generateConfig / registerInProject in the React, Web Components, jQuery and Angular base templates now default options to {}. Previously a missing options crashed on the first property access.
  • JSX self-closing elements without attributes are now created with an empty attribute list instead of undefined (core AST transformer and ReactTypeScriptFileUpdate). Both print <Tag />.
  • Four project templates that never assigned dependencies now initialize it to []. Only component templates' dependencies are ever read.
  • Util.formatPackageJson: the sort reduce no longer relies on (a = b) && acc, which would have returned "" for an empty version string.
  • cli.run(args) is typed string | string[] instead of args = null. Every caller passes arguments, and yargs' parseAsync requires them.
  • list: the group map is an object instead of an array used as a map. It is only read through Object.keys, so the output is unchanged.
  • upgrade (CLI) and upgrade-packages (ng-schematics): a framework and project type that don't match each other in ignite-ui-cli.json (e.g. angular with igc-ts) used to crash with Cannot read properties of undefined (reading 'projectIds'). They now report the existing "No valid Ignite UI project template found to upgrade packages." error. A spec covers each command.
  • ng-schematics ng-new: the "folder exists" check now skips a missing name explicitly. It already returned false in that case.
  • ng-schematics: the unused IgxSchematicContext interface was removed; its extra fields were never read. Rules now use SchematicContext.

Related Issue

Closes #1613

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Refactoring / code cleanup
  • Build / CI configuration change

Affected Packages

  • igniteui-cli (packages/cli)
  • @igniteui/cli-core (packages/core)
  • @igniteui/angular-templates (packages/igx-templates)
  • @igniteui/angular-schematics (packages/ng-schematics)
  • @igniteui/mcp-server (packages/igniteui-mcp)

Checklist

  • I have tested my changes locally (npm run test)
  • I have built the project successfully (npm run build)
  • I have run the linter (npm run lint)
  • I have added/updated tests as needed
  • My changes do not introduce new warnings or errors

Additional Context

This is the last of three stacked PRs for #1613. It is based on #1850 (coverage), which is based on #1849 (bug fixes).

Verification

  • tsc with tsconfig.json and with tsconfig-pack.json: 0 errors.
  • npm run test: 767 specs pass (2 pending, unchanged).
  • npm run lint: 0 errors; the one warning (unused eslint-disable in packages/core/util/Schematics.ts) is already on master.
  • scripts/smoke-test.sh:
    • React and Web Components pass, including install and build.
    • All 220 ig add steps pass across the three frameworks.
    • The Angular project fails to install and build because of an unrelated upstream change. igniteui-angular@22.2.3, published 2026-10-19, is picked up by the templates' ~22.2.0. It needs igniteui-grid-lite@~0.11.0, while the grid-lite template pins ~0.10.0, and it rejects APIs the template payloads still use (igxButton="raised", actionStrip, IButtonGroupButton). This PR changes no template payloads (files/); a separate issue will cover it.

Notes for reviewers

  • scripts/versionScript.ts changes by one character (let version!: string;), needed because scripts/ compiles under the root tsconfig.json.

Follow-ups, out of scope here

  • packages/ng-schematics/tsconfig.json still reports 22 errors that predate this PR: 21 unused locals/parameters from its noUnused* options, and 1 esModuleInterop error in igx-templates/index.ts. CI doesn't build with this config.
  • spec/helpers/utils.ts filesDiff() applies transform1 to the second list and globs folderPath1 twice. That is a bug in the test helper; it was left as is to keep test behaviour unchanged.
  • cli.run still checks args ? yargs(args) : yargs, but since args is now required, the bare yargs branch can't be reached.

- enable "strict": true in tsconfig.json, tsconfig-pack.json and the
  ng-schematics tsconfig
- type lookup methods honestly (T | undefined / T | null) and fix all
  resulting compiler errors across core, cli, igx-templates,
  ng-schematics, scripts and specs
- add @types/through2 (core) and @types/resolve (cli) dev dependencies
@coveralls

coveralls commented Oct 20, 2026 •

Copy link
Copy Markdown

Coverage Status

Coverage is 95.369% — ipetrov/ts-strict-mode into ipetrov/igx-templates-coverage. No base build found for ipetrov/igx-templates-coverage.

- cli upgrade, ng-schematics upgrade-packages: skip template resolution
  when the framework and project type resolve to no project library and
  report the existing "No valid Ignite UI project template" error
  instead of failing with a TypeError
- add specs for both commands

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the strict-mode migration.

No open issues 🎉

What changed in this PR

Completes the strict-mode migration for #1613, building on the bug fixes in #1849 and test coverage in #1850. The changes align the CLI, shared core, templates, schematics, scripts, and specs with stricter TypeScript checks.

Changes:

  • Enables strict compilation and adds the missing development-time type packages.
  • Makes nullable lookup results, optional values, initialization assumptions, and public method signatures explicit.
  • Adds safe defaults and upgrade guards, with regression tests for mismatched framework/project types.
File Description
yarn.lock Locks the two added type packages.
tsconfig.json Enables strict development compilation.
tsconfig-pack.json Enables strict package compilation.
spec/​unit/​upgrade-spec.ts Types mocks and tests mismatched project types.
spec/​unit/​update-spec.ts Adds assertions for fixture lookups.
spec/​unit/​TypeScript-AST-Transformer-spec.ts Types callbacks and nullable test values.
spec/​unit/​ts-transform/​TypeScriptUtils-spec.ts Types the newline lookup map.
spec/​unit/​ts-transform/​Mock-FS.ts Asserts mock filesystem initialization.
spec/​unit/​TemplateManager-spec.ts Types mock libraries and module loaders.
spec/​unit/​ProjectConfig-spec.ts Adjusts the filesystem spy typing.
spec/​unit/​packageManager-spec.ts Types simulated process errors.
spec/​unit/​new-spec.ts Explicitly casts intentionally incomplete mocks.
spec/​unit/​GoogleAnalytic-spec.ts Types analytics spies.
spec/​unit/​DotnetTemplateManager-spec.ts Types nullable statuses and expected calls.
spec/​unit/​doc-spec.ts Types the module-loader callback’s this.
spec/​unit/​cli-spec.ts Adjusts command-handler spy typing.
spec/​unit/​BaseProjectLibrary-spec.ts Handles nullable component lookup types.
spec/​unit/​base-templates/​IgniteUIForAngularTemplate-spec.ts Types helper parameters and mocks.
spec/​unit/​add-spec.ts Updates the mock filesystem return type.
spec/​templates/​webcomponents-spec.ts Types template metadata and lookup assertions.
spec/​templates/​template-contracts-spec.ts Asserts registered projects resolve.
spec/​templates/​react-spec.ts Types template metadata and library lookups.
spec/​templates/​blazor-spec.ts Asserts expected libraries and projects exist.
spec/​templates/​angular-spec.ts Types template metadata and library lookups.
spec/​jasmine-runner.ts Explicitly casts the existing null argument.
spec/​helpers/​utils.ts Adds a type assertion without changing helper behavior.
spec/​helpers/​mocks.ts Types the mock library factory argument.
spec/​acceptance/​new-spec.ts Types the test folder variable.
scripts/​versionScript.ts Adds a definite-assignment assertion.
scripts/​changelogScript.ts Types nullable versions and lookup keys.
packages/​ng-schematics/​tsconfig.json Replaces individual checks with full strict mode.
packages/​ng-schematics/​src/​utils/​NgFileSystem.ts Allows nullable visitor entries.
packages/​ng-schematics/​src/​utils/​cli-config.ts Types caught errors and optional projects.
packages/​ng-schematics/​src/​upgrade-packages/​index.ts Guards missing project libraries.
packages/​ng-schematics/​src/​upgrade-packages/​index.spec.ts Tests the missing-library error path.
packages/​ng-schematics/​src/​prompt/​SchematicsPromptSession.ts Marks externally initialized session fields.
packages/​ng-schematics/​src/​ng-new/​schema.ts Clarifies initialized and optional options.
packages/​ng-schematics/​src/​ng-new/​index.ts Uses standard context types and narrows optional values.
packages/​ng-schematics/​src/​component/​schema.ts Clarifies required and optional component options.
packages/​ng-schematics/​src/​component/​index.ts Asserts the built-in Angular library exists.
packages/​ng-schematics/​src/​app-projects/​schema.ts Marks required options as initialized.
packages/​igx-templates/​igx-ts/​tree-grid/​tree-grid-custom/​index.ts Types configuration records and feature arrays.
packages/​igx-templates/​igx-ts/​projects/​ai-config/​index.ts Aligns the extra-configuration signature.
packages/​igx-templates/​igx-ts/​projects/​_base/​index.ts Types configuration input and generated variables.
packages/​igx-templates/​igx-ts/​hierarchical-grid/​hierarchical-grid-custom/​index.ts Types feature state and optional documentation URLs.
packages/​igx-templates/​igx-ts/​grid/​multi-column-headers/​index.ts Types extra-configuration storage and input.
packages/​igx-templates/​igx-ts/​grid/​grid-custom/​index.ts Types extra configuration and feature URLs.
packages/​igx-templates/​igx-ts/​calendar/​default/​index.ts Types extra-configuration storage and input.
packages/​igx-templates/​IgniteUIForAngularTemplate.ts Types metadata and defaults generation options.
packages/​igx-templates/​AngularTypeScriptFileUpdate.ts Types metadata access and guards optional AST values.
packages/​core/​util/​Util.ts Adds strict types and fixes dependency-sort accumulation.
packages/​core/​util/​Schematics.ts Adds assertions around tree reads and regex matches.
packages/​core/​util/​ProjectTemplateResolver.ts Makes upgrade eligibility a nullable type guard.
packages/​core/​util/​ProjectConfig.ts Types validation results and caught errors.
packages/​core/​util/​GoogleAnalytics.ts Types the request error callback.
packages/​core/​update/​Update.ts Types style extensions and workspace callbacks.
packages/​core/​update/​package-resolve.ts Types upgradeable-package lookup keys.
packages/​core/​typescript/​TypeScriptUtils.ts Declares explicit file-saving return types.
packages/​core/​typescript/​TypeScriptFileUpdate.ts Handles optional JSX settings and route identifiers.
packages/​core/​typescript/​TypeScriptAstTransformer.ts Types optional state and supplies empty JSX attributes.
packages/​core/​typescript/​TransformerFactories.ts Refines callback types, optional settings, and assertions.
packages/​core/​types/​types-typescript.ts Makes change-request nodes optional.
packages/​core/​types/​Template.ts Declares the registration return type.
packages/​core/​types/​ProjectLibrary.ts Exposes nullable lookup results.
packages/​core/​types/​BaseTemplate.ts Types extra-configuration input and return value.
packages/​core/​templates/​BaseTemplateManager.ts Exposes nullable framework and library results.
packages/​core/​templates/​BaseProjectLibrary.ts Types metadata, collections, and nullable lookups.
packages/​core/​templates/​BaseComponent.ts Marks subclass-initialized metadata.
packages/​core/​prompt/​TaskRunner.ts Initializes the nullable current task.
packages/​core/​prompt/​BasePromptSession.ts Types session state and asynchronous upgrade behavior.
packages/​core/​packages/​PackageManager.ts Types queued installs and process errors.
packages/​core/​package.json Adds development typings for through2.
packages/​cli/​templates/​webcomponents/​WebComponentsTypeScriptFileUpdate.ts Adds route and formatting assertions.
packages/​cli/​templates/​webcomponents/​igc-ts/​projects/​side-nav/​index.ts Adds a dependency-field initialization assertion.
packages/​cli/​templates/​webcomponents/​igc-ts/​projects/​empty/​index.ts Adds a dependency-field initialization assertion.
packages/​cli/​templates/​webcomponents/​igc-ts/​projects/​base/​index.ts Adds a dependency-field initialization assertion.
packages/​cli/​templates/​webcomponents/​igc-ts/​projects/​ai-config/​index.ts Initializes dependencies to an empty array.
packages/​cli/​templates/​webcomponents/​igc-ts/​projects/​_base/​index.ts Types extra-configuration input.
packages/​cli/​templates/​react/​ReactTypeScriptFileUpdate.ts Supplies empty JSX attributes and route assertions.
packages/​cli/​templates/​react/​igr-ts/​projects/​_base/​index.ts Initializes dependencies to an empty array.
packages/​cli/​templates/​jquery/​js/​tree-grid/​tree-grid/​index.ts Types configuration records and selected features.
packages/​cli/​templates/​jquery/​js/​tree-grid/​tree-grid-export/​index.ts Types configuration records and selected features.
packages/​cli/​templates/​jquery/​js/​tree-grid/​tree-grid-editing/​index.ts Types configuration records and selected features.
packages/​cli/​templates/​jquery/​js/​tree-grid/​tree-grid-custom/​index.ts Types configuration records and selected features.
packages/​cli/​templates/​jquery/​js/​projects/​empty/​index.ts Initializes dependencies to an empty array.
packages/​cli/​templates/​jquery/​js/​hierarchical-grid/​hierarchical-grid/​index.ts Types configuration records and selected features.
packages/​cli/​templates/​jquery/​js/​hierarchical-grid/​hierarchical-grid-export/​index.ts Types configuration records and selected features.
packages/​cli/​templates/​jquery/​js/​hierarchical-grid/​hierarchical-grid-editing/​index.ts Types configuration records and selected features.
packages/​cli/​templates/​jquery/​js/​hierarchical-grid/​hierarchical-grid-custom/​index.ts Types configuration records and selected features.
packages/​cli/​templates/​jquery/​js/​grid/​grid/​index.ts Types configuration records and selected features.
packages/​cli/​templates/​jquery/​js/​grid/​grid-templating/​index.ts Types configuration records and selected features.
packages/​cli/​templates/​jquery/​js/​grid/​grid-export/​index.ts Types configuration records and selected features.
packages/​cli/​templates/​jquery/​js/​grid/​grid-editing/​index.ts Types configuration records and selected features.
packages/​cli/​templates/​jquery/​js/​grid/​grid-custom/​index.ts Types configuration records and selected features.
packages/​cli/​templates/​jquery/​js/​editors/​index.ts Marks externally initialized editor metadata.
packages/​cli/​templates/​jquery/​js/​custom-templates/​file-explorer/​index.ts Types configuration records and selected features.
packages/​cli/​templates/​blazor/​igb/​projects/​ai-config/​index.ts Initializes dependencies to an empty array.
packages/​cli/​package.json Adds development typings for resolve.
packages/​cli/​lib/​templates/​jQueryTemplate.ts Types metadata and defaults generation options.
packages/​cli/​lib/​templates/​IgniteUIForWebComponentsTemplate.ts Types metadata and defaults optional arguments.
packages/​cli/​lib/​templates/​IgniteUIForReactTemplate.ts Types metadata and defaults optional arguments.
packages/​cli/​lib/​TemplateManager.ts Declares nullable template-loading results.
packages/​cli/​lib/​project-utility/​GridHelper.ts Types feature records and mutation methods.
packages/​cli/​lib/​MultiTemplateComponent.ts Types constructors, metadata, and lookup results.
packages/​cli/​lib/​commands/​upgrade.ts Guards missing libraries and types caught errors.
packages/​cli/​lib/​commands/​types.ts Declares handler returns and browser-target types.
packages/​cli/​lib/​commands/​new.ts Adds assertions for validated command arguments.
packages/​cli/​lib/​commands/​list.ts Uses a typed group object and nullable framework lookup.
packages/​cli/​lib/​commands/​generate.ts Adds assertions for required command arguments.
packages/​cli/​lib/​commands/​config.ts Types dynamic configuration access and validation values.
packages/​cli/​lib/​commands/​ai-config.ts Asserts the selected framework resolves.
packages/​cli/​lib/​commands/​add.ts Adds assertions for validated template arguments.
packages/​cli/​lib/​cli.ts Requires string or string-array arguments.

Review effort: Balanced

@ivanvpetrov
ivanvpetrov marked this pull request as ready for review November 2, 2026 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enable TypeScript strict mode across the codebase

3 participants