diff --git a/common/changes/@rushstack/heft-typescript-plugin/heft-typescript-plugin-typescript-56-support_2024-10-13-22-44.json b/common/changes/@rushstack/heft-typescript-plugin/heft-typescript-plugin-typescript-56-support_2024-10-13-22-44.json new file mode 100644 index 00000000000..9250e00f4ad --- /dev/null +++ b/common/changes/@rushstack/heft-typescript-plugin/heft-typescript-plugin-typescript-56-support_2024-10-13-22-44.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@rushstack/heft-typescript-plugin", + "comment": "Support typescript v5.6", + "type": "patch" + } + ], + "packageName": "@rushstack/heft-typescript-plugin" +} \ No newline at end of file diff --git a/heft-plugins/heft-typescript-plugin/src/TypeScriptBuilder.ts b/heft-plugins/heft-typescript-plugin/src/TypeScriptBuilder.ts index f1f4db242a9..4291e24cbcc 100644 --- a/heft-plugins/heft-typescript-plugin/src/TypeScriptBuilder.ts +++ b/heft-plugins/heft-typescript-plugin/src/TypeScriptBuilder.ts @@ -11,7 +11,11 @@ import { JsonFile, type IPackageJson, Path, FileError } from '@rushstack/node-co import type { ITerminal } from '@rushstack/terminal'; import type { IScopedLogger } from '@rushstack/heft'; -import type { ExtendedTypeScript, IExtendedSolutionBuilder } from './internalTypings/TypeScriptInternals'; +import type { + ExtendedBuilderProgram, + ExtendedTypeScript, + IExtendedSolutionBuilder +} from './internalTypings/TypeScriptInternals'; import type { ITypeScriptConfigurationJson } from './TypeScriptPlugin'; import type { PerformanceMeasurer } from './Performance'; import type { @@ -111,7 +115,7 @@ const OLDEST_SUPPORTED_TS_MAJOR_VERSION: number = 2; const OLDEST_SUPPORTED_TS_MINOR_VERSION: number = 9; const NEWEST_SUPPORTED_TS_MAJOR_VERSION: number = 5; -const NEWEST_SUPPORTED_TS_MINOR_VERSION: number = 4; +const NEWEST_SUPPORTED_TS_MINOR_VERSION: number = 6; interface ITypeScriptTool { ts: ExtendedTypeScript; @@ -1300,9 +1304,10 @@ export class TypeScriptBuilder { function getFilesToTranspileFromBuilderProgram( builderProgram: TTypescript.BuilderProgram ): Map { - const changedFilesSet: Set = ( - builderProgram as unknown as { getState(): { changedFilesSet: Set } } - ).getState().changedFilesSet; + const program: ExtendedBuilderProgram = builderProgram as unknown as ExtendedBuilderProgram; + // getState was removed in Typescript 5.6, replaced with state + const changedFilesSet: Set = (program.state ?? program.getState()).changedFilesSet; + const filesToTranspile: Map = new Map(); for (const fileName of changedFilesSet) { const sourceFile: TTypescript.SourceFile | undefined = builderProgram.getSourceFile(fileName); diff --git a/heft-plugins/heft-typescript-plugin/src/internalTypings/TypeScriptInternals.ts b/heft-plugins/heft-typescript-plugin/src/internalTypings/TypeScriptInternals.ts index cfcc643e8a3..c330ac96769 100644 --- a/heft-plugins/heft-typescript-plugin/src/internalTypings/TypeScriptInternals.ts +++ b/heft-plugins/heft-typescript-plugin/src/internalTypings/TypeScriptInternals.ts @@ -98,3 +98,14 @@ export interface IExtendedTypeScript { } export type ExtendedTypeScript = typeof TTypescript & IExtendedTypeScript; + +export type ExtendedBuilderProgram = TTypescript.BuilderProgram & { + /** + * Typescript 5.6+ + */ + state?: { changedFilesSet: Set }; + /** + * Typescript < 5.6 + */ + getState(): { changedFilesSet: Set }; +};