Skip to content

Commit 0301cf6

Browse files
crisbetodgp1130
authored andcommitted
build: prepare TypeScript 4.7
Expands the version range to allow TypeScript 4.7 and makes the necessary code changes in order to support it.
1 parent c99f43c commit 0301cf6

File tree

20 files changed

+60
-48
lines changed

20 files changed

+60
-48
lines changed

goldens/public-api/angular_devkit/schematics/index.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export function applyContentTemplate<T>(options: T): FileOperator;
7171
export function applyPathTemplate<T extends PathTemplateData>(data: T, options?: PathTemplateOptions): FileOperator;
7272

7373
// @public (undocumented)
74-
export function applyTemplates<T>(options: T): Rule;
74+
export function applyTemplates<T extends object>(options: T): Rule;
7575

7676
// @public (undocumented)
7777
export function applyToSubtree(path: string, rules: Rule[]): Rule;
@@ -904,11 +904,11 @@ export class TaskScheduler {
904904
// (undocumented)
905905
finalize(): ReadonlyArray<TaskInfo>;
906906
// (undocumented)
907-
schedule<T>(taskConfiguration: TaskConfiguration<T>): TaskId;
907+
schedule<T extends object>(taskConfiguration: TaskConfiguration<T>): TaskId;
908908
}
909909

910910
// @public (undocumented)
911-
export function template<T>(options: T): Rule;
911+
export function template<T extends object>(options: T): Rule;
912912

913913
// @public (undocumented)
914914
export const TEMPLATE_FILENAME_RE: RegExp;
@@ -939,7 +939,7 @@ export const TreeSymbol: symbol;
939939
// @public
940940
export interface TypedSchematicContext<CollectionMetadataT extends object, SchematicMetadataT extends object> {
941941
// (undocumented)
942-
addTask<T>(task: TaskConfigurationGenerator<T>, dependencies?: Array<TaskId>): TaskId;
942+
addTask<T extends object>(task: TaskConfigurationGenerator<T>, dependencies?: Array<TaskId>): TaskId;
943943
// (undocumented)
944944
readonly debug: boolean;
945945
// (undocumented)

goldens/public-api/angular_devkit/schematics/testing/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ export class SchematicTestRunner {
2525
// (undocumented)
2626
registerCollection(collectionName: string, collectionPath: string): void;
2727
// (undocumented)
28-
runExternalSchematicAsync<SchematicSchemaT>(collectionName: string, schematicName: string, opts?: SchematicSchemaT, tree?: Tree_2): Observable<UnitTestTree>;
28+
runExternalSchematicAsync<SchematicSchemaT extends object>(collectionName: string, schematicName: string, opts?: SchematicSchemaT, tree?: Tree_2): Observable<UnitTestTree>;
2929
// (undocumented)
30-
runSchematicAsync<SchematicSchemaT>(schematicName: string, opts?: SchematicSchemaT, tree?: Tree_2): Observable<UnitTestTree>;
30+
runSchematicAsync<SchematicSchemaT extends object>(schematicName: string, opts?: SchematicSchemaT, tree?: Tree_2): Observable<UnitTestTree>;
3131
// (undocumented)
3232
get tasks(): TaskConfiguration[];
3333
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@
169169
"magic-string": "0.26.1",
170170
"mini-css-extract-plugin": "2.6.0",
171171
"minimatch": "5.0.1",
172-
"ng-packagr": "14.0.0-next.5",
172+
"ng-packagr": "14.0.0-next.8",
173173
"node-fetch": "^2.2.0",
174174
"npm-package-arg": "9.0.2",
175175
"open": "8.4.0",

packages/angular/cli/src/command-builder/architect-base-command-module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export interface MissingTargetChoice {
3232
value: string;
3333
}
3434

35-
export abstract class ArchitectBaseCommandModule<T>
35+
export abstract class ArchitectBaseCommandModule<T extends object>
3636
extends CommandModule<T>
3737
implements CommandModuleImplementation<T>
3838
{

packages/angular/cli/src/command-builder/utilities/command.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { CommandContext, CommandModule, CommandModuleImplementation } from '../c
1212
export const demandCommandFailureMessage = `You need to specify a command before moving on. Use '--help' to view the available commands.`;
1313

1414
export function addCommandModuleToYargs<
15-
T,
15+
T extends object,
1616
U extends Partial<CommandModuleImplementation> & {
1717
new (context: CommandContext): Partial<CommandModuleImplementation> & CommandModule;
1818
},

packages/angular_devkit/architect/src/create-builder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ export function createBuilder<OptT = json.JsonObject, OutT extends BuilderOutput
202202
context.reportRunning();
203203
let result;
204204
try {
205-
result = fn(i.options as OptT, context);
205+
result = fn(i.options as unknown as OptT, context);
206206
if (isBuilderOutput(result)) {
207207
result = of(result);
208208
} else if (!isObservable(result) && isAsyncIterable(result)) {

packages/angular_devkit/build_angular/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
"ng-packagr": "^14.0.0 || ^14.0.0-next",
8181
"protractor": "^7.0.0",
8282
"tailwindcss": "^2.0.0 || ^3.0.0",
83-
"typescript": "~4.6.2"
83+
"typescript": ">=4.6.2 <4.8"
8484
},
8585
"peerDependenciesMeta": {
8686
"@angular/localize": {

packages/angular_devkit/build_angular/src/testing/builder-harness.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export class BuilderHarness<T> {
113113
return this;
114114
}
115115

116-
withBuilderTarget<O>(
116+
withBuilderTarget<O extends object>(
117117
target: string,
118118
handler: BuilderHandlerFn<O & json.JsonObject>,
119119
options?: O,
@@ -178,12 +178,12 @@ export class BuilderHarness<T> {
178178
getOptions: async (project, target, configuration) => {
179179
this.validateProjectName(project);
180180
if (target === this.targetName) {
181-
return this.options.get(configuration ?? null) ?? {};
181+
return (this.options.get(configuration ?? null) ?? {}) as json.JsonObject;
182182
} else if (configuration !== undefined) {
183183
// Harness builder targets currently do not support configurations
184184
return {};
185185
} else {
186-
return (this.builderTargets.get(target)?.options as json.JsonObject) || {};
186+
return (this.builderTargets.get(target)?.options || {}) as json.JsonObject;
187187
}
188188
},
189189
hasTarget: async (project, target) => {

packages/angular_devkit/core/src/json/schema/registry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ export class CoreSchemaRegistry implements SchemaRegistry {
402402
throw new Error(source);
403403
}
404404

405-
this._sourceMap.set(source, provider);
405+
this._sourceMap.set(source, provider as unknown as SmartDefaultProvider<{}>);
406406

407407
if (!this._smartDefaultKeyword) {
408408
this._smartDefaultKeyword = true;

packages/angular_devkit/core/src/utils/object.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function deepCopy<T>(value: T): T {
1212
if (Array.isArray(value)) {
1313
return value.map((o) => deepCopy(o)) as unknown as T;
1414
} else if (value && typeof value === 'object') {
15-
const valueCasted = value as {
15+
const valueCasted = value as unknown as {
1616
[copySymbol]?: T;
1717
toJSON?: () => string;
1818
// eslint-disable-next-line @typescript-eslint/no-explicit-any

packages/angular_devkit/core/src/workspace/json/reader_spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ describe('JSON WorkspaceDefinition Tracks Workspace Changes', () => {
317317

318318
const workspace = await readJsonWorkspace('', host);
319319

320-
Object.assign(workspace.extensions['x-foo'], { x: 9, y: 8 }, { z: 7 });
320+
Object.assign(workspace.extensions['x-foo']!, { x: 9, y: 8 }, { z: 7 });
321321
expect(workspace.extensions['x-foo']).toEqual({
322322
is: ['good', 'great', 'awesome'],
323323
x: 9,
@@ -355,7 +355,7 @@ describe('JSON WorkspaceDefinition Tracks Workspace Changes', () => {
355355
const workspace = await readJsonWorkspace('', host);
356356

357357
workspace.extensions['x-foo'] = Object.assign(
358-
workspace.extensions['x-foo'],
358+
workspace.extensions['x-foo']!,
359359
{ x: 9, y: 8 },
360360
{ z: 7 },
361361
);

packages/angular_devkit/schematics/src/engine/engine.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export class TaskScheduler {
141141
return new Set(tasks);
142142
}
143143

144-
schedule<T>(taskConfiguration: TaskConfiguration<T>): TaskId {
144+
schedule<T extends object>(taskConfiguration: TaskConfiguration<T>): TaskId {
145145
const dependencies = this._mapDependencies(taskConfiguration.dependencies);
146146
const priority = this._calculatePriority(dependencies);
147147

@@ -275,7 +275,10 @@ export class SchematicEngine<CollectionT extends object, SchematicT extends obje
275275
const host = this._host;
276276
this._taskSchedulers.push(taskScheduler);
277277

278-
function addTask<T>(task: TaskConfigurationGenerator<T>, dependencies?: Array<TaskId>): TaskId {
278+
function addTask<T extends object>(
279+
task: TaskConfigurationGenerator<T>,
280+
dependencies?: Array<TaskId>,
281+
): TaskId {
279282
const config = task.toConfiguration();
280283

281284
if (!host.hasTaskExecutor(config.name)) {

packages/angular_devkit/schematics/src/engine/interface.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,10 @@ export interface TypedSchematicContext<
198198
readonly schematic: Schematic<CollectionMetadataT, SchematicMetadataT>;
199199
readonly strategy: MergeStrategy;
200200
readonly interactive: boolean;
201-
addTask<T>(task: TaskConfigurationGenerator<T>, dependencies?: Array<TaskId>): TaskId;
201+
addTask<T extends object>(
202+
task: TaskConfigurationGenerator<T>,
203+
dependencies?: Array<TaskId>,
204+
): TaskId;
202205
}
203206

204207
/**

packages/angular_devkit/schematics/src/rules/template.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,24 +163,24 @@ export function renameTemplateFiles(): Rule {
163163
);
164164
}
165165

166-
export function template<T>(options: T): Rule {
166+
export function template<T extends object>(options: T): Rule {
167167
return chain([
168168
contentTemplate(options),
169169
// Force cast to PathTemplateData. We need the type for the actual pathTemplate() call,
170170
// but in this case we cannot do anything as contentTemplate are more permissive.
171171
// Since values are coerced to strings in PathTemplates it will be fine in the end.
172-
pathTemplate((options as {}) as PathTemplateData),
172+
pathTemplate(options as {} as PathTemplateData),
173173
]);
174174
}
175175

176-
export function applyTemplates<T>(options: T): Rule {
176+
export function applyTemplates<T extends object>(options: T): Rule {
177177
return forEach(
178178
when(
179179
(path) => path.endsWith('.template'),
180180
composeFileOperators([
181181
applyContentTemplate(options),
182182
// See above for this weird cast.
183-
applyPathTemplate((options as {}) as PathTemplateData),
183+
applyPathTemplate(options as {} as PathTemplateData),
184184
(entry) => {
185185
return {
186186
content: entry.content,

packages/angular_devkit/schematics/testing/schematic-test-runner.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export class SchematicTestRunner {
7878
this._engineHost.registerCollection(collectionName, collectionPath);
7979
}
8080

81-
runSchematicAsync<SchematicSchemaT>(
81+
runSchematicAsync<SchematicSchemaT extends object>(
8282
schematicName: string,
8383
opts?: SchematicSchemaT,
8484
tree?: Tree,
@@ -92,7 +92,7 @@ export class SchematicTestRunner {
9292
.pipe(map((tree) => new UnitTestTree(tree)));
9393
}
9494

95-
runExternalSchematicAsync<SchematicSchemaT>(
95+
runExternalSchematicAsync<SchematicSchemaT extends object>(
9696
collectionName: string,
9797
schematicName: string,
9898
opts?: SchematicSchemaT,

packages/ngtools/webpack/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"dependencies": {},
2424
"peerDependencies": {
2525
"@angular/compiler-cli": "^14.0.0 || ^14.0.0-next",
26-
"typescript": "~4.6.2",
26+
"typescript": ">=4.6.2 <4.8",
2727
"webpack": "^5.54.0"
2828
},
2929
"devDependencies": {

packages/ngtools/webpack/src/ivy/host.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,35 +210,40 @@ export function augmentHostWithNgcc(
210210

211211
if (host.resolveTypeReferenceDirectives) {
212212
const baseResolveTypeReferenceDirectives = host.resolveTypeReferenceDirectives;
213-
host.resolveTypeReferenceDirectives = function (names: string[], ...parameters) {
213+
host.resolveTypeReferenceDirectives = function (
214+
names: string[] | ts.FileReference[],
215+
...parameters
216+
) {
214217
return names.map((name) => {
215-
const result = baseResolveTypeReferenceDirectives.call(host, [name], ...parameters);
218+
const fileName = typeof name === 'string' ? name : name.fileName;
219+
const result = baseResolveTypeReferenceDirectives.call(host, [fileName], ...parameters);
216220

217221
if (result[0] && ngcc) {
218-
ngcc.processModule(name, result[0]);
222+
ngcc.processModule(fileName, result[0]);
219223
}
220224

221225
return result[0];
222226
});
223227
};
224228
} else {
225229
host.resolveTypeReferenceDirectives = function (
226-
moduleNames: string[],
230+
moduleNames: string[] | ts.FileReference[],
227231
containingFile: string,
228232
redirectedReference: ts.ResolvedProjectReference | undefined,
229233
options: ts.CompilerOptions,
230234
) {
231235
return moduleNames.map((name) => {
236+
const fileName = typeof name === 'string' ? name : name.fileName;
232237
const result = ts.resolveTypeReferenceDirective(
233-
name,
238+
fileName,
234239
containingFile,
235240
options,
236241
host,
237242
redirectedReference,
238243
).resolvedTypeReferenceDirective;
239244

240245
if (result && ngcc) {
241-
ngcc.processModule(name, result);
246+
ngcc.processModule(fileName, result);
242247
}
243248

244249
return result;

packages/schematics/angular/utility/latest-versions/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"karma-jasmine-html-reporter": "~1.7.0",
1212
"karma-jasmine": "~5.0.0",
1313
"karma": "~6.3.0",
14-
"ng-packagr": "^14.0.0-next.2",
14+
"ng-packagr": "^14.0.0-next.8",
1515
"rxjs": "~7.5.0",
1616
"tslib": "^2.3.0",
1717
"ts-node": "~10.7.0",

tests/legacy-cli/e2e/tests/misc/third-party-decorators.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ import { updateJsonFile } from '../../utils/project';
66
export default async function () {
77
await updateJsonFile('package.json', (packageJson) => {
88
// Install ngrx
9-
packageJson['dependencies']['@ngrx/effects'] = '^9.1.0';
10-
packageJson['dependencies']['@ngrx/schematics'] = '^9.1.0';
11-
packageJson['dependencies']['@ngrx/store'] = '^9.1.0';
12-
packageJson['dependencies']['@ngrx/store-devtools'] = '^9.1.0';
9+
packageJson['dependencies']['@ngrx/effects'] = '^13.2.0';
10+
packageJson['dependencies']['@ngrx/schematics'] = '^13.2.0';
11+
packageJson['dependencies']['@ngrx/store'] = '^13.2.0';
12+
packageJson['dependencies']['@ngrx/store-devtools'] = '^13.2.0';
13+
14+
// TODO(crisbeto): ngrx hasn't been updated for TS 4.7 yet.
15+
packageJson['devDependencies']['typescript'] = '~4.6.2';
1316
});
1417

1518
await installWorkspacePackages();

yarn.lock

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@
177177

178178
"@angular/dev-infra-private@https://github.com/angular/dev-infra-private-builds.git#54c89d2b5ea8a35006eafdcd4e24abab6a7c73b6":
179179
version "0.0.0-d9f50abe777f5077aee75a35f2fe65bb478638b5"
180-
uid "54c89d2b5ea8a35006eafdcd4e24abab6a7c73b6"
181180
resolved "https://github.com/angular/dev-infra-private-builds.git#54c89d2b5ea8a35006eafdcd4e24abab6a7c73b6"
182181
dependencies:
183182
"@angular-devkit/build-angular" "14.0.0-next.13"
@@ -5349,7 +5348,7 @@ glob-to-regexp@^0.4.1:
53495348
resolved "https://registry.yarnpkg.com/glob-to-regexp/-/glob-to-regexp-0.4.1.tgz#c75297087c851b9a578bd217dd59a92f59fe546e"
53505349
integrity sha512-lkX1HJXwyMcprw/5YUZc2s7DrpAiHB21/V+E1rHUrVNokkvB6bqMzT0VfV6/86ZNabt1k14YOIaT7nDvOX3Iiw==
53515350

5352-
glob@8.0.1, glob@^8.0.1:
5351+
glob@8.0.1, glob@^8.0.0, glob@^8.0.1:
53535352
version "8.0.1"
53545353
resolved "https://registry.yarnpkg.com/glob/-/glob-8.0.1.tgz#00308f5c035aa0b2a447cd37ead267ddff1577d3"
53555354
integrity sha512-cF7FYZZ47YzmCu7dDy50xSRRfO3ErRfrXuLZcNIuyiJEco0XSrGtuilG19L5xp3NcwTx7Gn+X6Tv3fmsUPTbow==
@@ -5372,7 +5371,7 @@ glob@^6.0.1:
53725371
once "^1.3.0"
53735372
path-is-absolute "^1.0.0"
53745373

5375-
glob@^7.0.0, glob@^7.0.3, glob@^7.0.6, glob@^7.1.1, glob@^7.1.3, glob@^7.1.4, glob@^7.1.6, glob@^7.1.7, glob@^7.2.0:
5374+
glob@^7.0.0, glob@^7.0.3, glob@^7.0.6, glob@^7.1.1, glob@^7.1.3, glob@^7.1.4, glob@^7.1.6, glob@^7.1.7:
53765375
version "7.2.0"
53775376
resolved "https://registry.yarnpkg.com/glob/-/glob-7.2.0.tgz#d15535af7732e02e948f4c41628bd910293f6023"
53785377
integrity sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==
@@ -7198,10 +7197,10 @@ next-tick@1, next-tick@^1.1.0:
71987197
resolved "https://registry.yarnpkg.com/next-tick/-/next-tick-1.1.0.tgz#1836ee30ad56d67ef281b22bd199f709449b35eb"
71997198
integrity sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==
72007199

7201-
ng-packagr@14.0.0-next.5:
7202-
version "14.0.0-next.5"
7203-
resolved "https://registry.yarnpkg.com/ng-packagr/-/ng-packagr-14.0.0-next.5.tgz#40a308b358b1294c673e5bcaee6f656bda7d50b8"
7204-
integrity sha512-eaGDbrYRuQ17NzkasfFGdjEz1lhevLB4Sp4dCLbqJhormKwOSCtTwuxzKBcdNCzG0sJ0PBAWznuaateUvhFyAQ==
7200+
ng-packagr@14.0.0-next.8:
7201+
version "14.0.0-next.8"
7202+
resolved "https://registry.yarnpkg.com/ng-packagr/-/ng-packagr-14.0.0-next.8.tgz#51b7c6bf8f4dce8cffa2063b22ae3142c8714354"
7203+
integrity sha512-xFIFVVgOHd8wIESq+SKgEQrYB24H0+sqb53ySHpdN5KLnVGbZ52BUtPfOOcscwwd+zaeE1RuKBhPfCbfxiiILA==
72057204
dependencies:
72067205
"@rollup/plugin-json" "^4.1.0"
72077206
"@rollup/plugin-node-resolve" "^13.1.3"
@@ -7214,7 +7213,7 @@ ng-packagr@14.0.0-next.5:
72147213
dependency-graph "^0.11.0"
72157214
esbuild-wasm "^0.14.29"
72167215
find-cache-dir "^3.3.2"
7217-
glob "^7.2.0"
7216+
glob "^8.0.0"
72187217
injection-js "^2.4.0"
72197218
jsonc-parser "^3.0.0"
72207219
less "^4.1.2"
@@ -9030,7 +9029,6 @@ sass@1.51.0, sass@^1.49.9:
90309029

90319030
"sauce-connect-proxy@https://saucelabs.com/downloads/sc-4.7.1-linux.tar.gz":
90329031
version "0.0.0"
9033-
uid e5d7f82ad98251a653d1b0537f1103e49eda5e11
90349032
resolved "https://saucelabs.com/downloads/sc-4.7.1-linux.tar.gz#e5d7f82ad98251a653d1b0537f1103e49eda5e11"
90359033

90369034
saucelabs@^1.5.0:

0 commit comments

Comments
 (0)