Using any
or object
types resulted in no type checking. Typescipt is used because we want type checking :-).
Whenever we copy and paste some code snippet, it is a signal to us that we need helper function. Example
if (value1 === undefined || value1 === null || value1 === "") {
console.error("value is missing");
}
if (value2 === undefined || value2 === null || value2 === "") {
console.error("value is missing");
}
if (value3 === undefined || value3 === null || value3 === "") {
console.error("value is missing");
}
...
can be
const printErrorWhenValueIsMissing = (val: string | undefined || null) => {
if (val === undefined || val === null || val === "") {
console.error("value is missing");
}
}
printErrorWhenValueIsMissing(value1);
printErrorWhenValueIsMissing(value2);
printErrorWhenValueIsMissing(value3);
...
Create async function only went it is need. Having sync
for non async function resulted in creation of Promise
object which is not needed.
Example
let str = "";
clusters.forEach(cluster => {
str += cluster + ", ";
});
str = str.substr(0, str.length - 2);
can be
const str = clusters.join(", ");
Example
const clusters: string[] = [];
if (tags) {
tags.forEach((itag: ITag) => {
clusters.push(itag.name);
});
}
can be
const clusters: string[] = tags ? tags.map(tag => tag.name) : [];
Example
const clusters: ICluster[] = [];
if (status) {
status.forEach((stat: ICluster) => {
if (manifestCommitId === stat.commit) {
clusters.push(stat);
}
});
}
return clusters;
can be
return (status || []).filter(
stat => manifestCommitId === stat.commit
);