We have automated checking for prettier/lint/typescript errors in our CI tooling (VSC/Github).
Recently one or two of the dependabot updates has started failing ts scripts in the process in several different places and different ts files. As I'm not a ts person and have taken this over from someone else, I'd like some help in understanding. I've looked at various other posts for the same error, but still don't know what to change in my instance, and I don't want to change something incorrectly.
- Error:
Error: salesforce-utils/src/bin/cancel-deploy.ts(19,29): error TS7053: Element implicitly has an 'any' type because expression of type '"save-progress-file"' can't be used to index type '{ [x: string]: unknown; "save-progress-file": string; _: (string | number)[]; $0: string; } | Promise<{ [x: string]: unknown; "save-progress-file": string; _: (string | number)[]; $0: string; }>'.
Property 'save-progress-file' does not exist on type '{ [x: string]: unknown; "save-progress-file": string; _: (string | number)[]; $0: string; } | Promise<{ [x: string]: unknown; "save-progress-file": string; _: (string | number)[]; $0: string; }>'.
File cancel-deploy.ts, and it's line 19 it's moaning about this.saveProgressFile = argv["save-progress-file"];:
import yargs = require("yargs");
import { State } from "../deploy";
class Config {
saveProgressFile: string;
constructor() {
const argv = yargs
.scriptName("cancel-deploy")
.describe(
"save-progress-file",
"Save a file with the progress that can be used to resume. Default: [cluster-developer-name].deploy-log.json."
)
.alias("save-progress-file", "s")
.string("save-progress-file")
.demandOption("save-progress-file").argv;
this.saveProgressFile = argv["save-progress-file"];
}
...etc
- Same error, different file, where it has an error for each of the last lines in this snippet:
constructor() {
const argv = yargs
.scriptName("deploy")
.describe("cluster-config-file", "The file configuring the SF2SF sync.")
.alias("cluster-config-file", "f")
.string("cluster-config-file")
.required("cluster-config-file")
.array("cluster-config-file")
.describe("validate", "Only do the validate part of the deploy")
.alias("validate", "v")
.boolean("validate")
.default("validate", false)
.describe("quick", "Don't wait for job to complete")
.alias("quick", "q")
.boolean("quick")
.default("quick", false)
.describe("resume", "Resume the deploy described in the file")
.alias("resume", "r")
.string("resume")
.string("test-level")
.alias("test-level", "l")
.describe("test-level", "Passed through to the sfdx validate command")
.default("test-level", "RunLocalTests")
.describe(
"save-progress-file",
"Save a file with the progress that can be used to resume. Default: [cluster-developer-name].deploy-log.json."
)
.alias("save-progress-file", "s")
.string("save-progress-file")
.describe("skip-validation", "Skip the validation process, just deploy")
.boolean("skip-validation")
.default("skip-validation", false).argv;
this.clusterConfigFiles = argv["cluster-config-file"];
this.validateOnly = argv["validate"];
this.quick = argv["quick"];
this.resume = argv["resume"];
this.testLevel = argv["test-level"];
this.saveProgressFile = argv["save-progress-file"];
this.skipValidation = argv["skip-validation"];
}
And several more ts files with the same setup of a constructor with args, then assigning them.
How do I fix these? Any ts updates are now failing our CI process because the scripts are no longer passing the check. I can turn off the typecheck, but would rather fix the files (if that's the better solution).
- I have another Dependabot update which is also throwing other errors:
Error: salesforce-utils/src/bin/subscribed-fields.ts(190,11): error TS2349: This expression is not callable
Error: salesforce-utils/src/bin/subscribed-fields.ts(197,22): error TS2571: Object is of type 'unknown'.
Error: salesforce-utils/src/bin/subscribed-fields.ts(207,11): error TS2345: Argument of type 'unknown' is not assignable to parameter of type 'Connection'.
Below is the part of the ts file where the errors occur:
(async (): Promise<void> => {
const argv = new Config();
const { clusterConfigFile, concurrency } = argv;
const clusterConfig = await SyndexClusterConfig.fromPath(clusterConfigFile);
const browser = await launch();
const connections = flatten(
await pAll(
clusterConfig.usernames.map(
(username) => (): Promise<Connection[]> =>
loginAndGetConnections(browser, username)
),
{ concurrency }
)
).filter((conn) => conn.isActive);
const differences: SubscribedFieldUpdate[] = [];
await pAll(
connections.map(
(connection) => (): Promise<void> =>
checkDifferencesForConnectionSafely(
argv,
browser,
connection,
differences
)
),
{ concurrency }
);
const result = differences.map(
({ connection, connectionObject, connectionField, newValue }) => ({
username: connection.username,
connection: connection.name,
object: connectionObject.name,
field: connectionField.name,
oldValue: (connectionField.value && connectionField.value.name) || "",
newValue: (newValue && newValue.name) || ""
})
);
console.log(JSON.stringify(result, null, " "));
await browser.close();
})();