Skip to content

Commit cb9ee24

Browse files
clydinalan-agius4
authored andcommitted
refactor(@angular-devkit/schematics): assert catch clause variable type before usage
Prepares the `@angular-devkit/schematics` package for the eventual change of enabling the TypeScript `useUnknownInCatchVariables` option. This option provides additional code safety by ensuring that the catch clause variable is the proper type before attempting to access its properties. Similar changes will be needed in the other packages in the repository prior to enabling `useUnknownInCatchVariables`.
1 parent 2edb2a0 commit cb9ee24

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export function applyContentTemplate<T>(options: T): FileOperator {
6363
content: Buffer.from(templateImpl(decodedContent, {})(options)),
6464
};
6565
} catch (e) {
66-
if (e.code === 'ERR_ENCODING_INVALID_ENCODED_DATA') {
66+
if ((e as NodeJS.ErrnoException).code === 'ERR_ENCODING_INVALID_ENCODED_DATA') {
6767
return entry;
6868
}
6969

packages/angular_devkit/schematics/tools/node-module-engine-host.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class NodeModulesEngineHost extends FileSystemEngineHostBase {
6767

6868
collectionPath = this.resolve(schematics, packageJsonPath, references);
6969
} catch (e) {
70-
if (e.code !== 'MODULE_NOT_FOUND') {
70+
if ((e as NodeJS.ErrnoException).code !== 'MODULE_NOT_FOUND') {
7171
throw e;
7272
}
7373
}
@@ -77,7 +77,7 @@ export class NodeModulesEngineHost extends FileSystemEngineHostBase {
7777
try {
7878
collectionPath = require.resolve(name, resolveOptions);
7979
} catch (e) {
80-
if (e.code !== 'MODULE_NOT_FOUND') {
80+
if ((e as NodeJS.ErrnoException).code !== 'MODULE_NOT_FOUND') {
8181
throw e;
8282
}
8383
}

0 commit comments

Comments
 (0)