Bump to TypeScript 5.5 and enable noImplicitAny
This commit upgrades TypeScript from 5.4 to 5.5 and enables the
`noImplicitAny` option for stricter type checking. It refactors code to
comply with `noImplicitAny` and adapts to new TypeScript features and
limitations.
Key changes:
- Migrate from TypeScript 5.4 to 5.5
- Enable `noImplicitAny` for stricter type checking
- Refactor code to comply with new TypeScript features and limitations
Other supporting changes:
- Refactor progress bar handling for type safety
- Drop 'I' prefix from interfaces to align with new code convention
- Update TypeScript target from `ES2017` and `ES2018`.
This allows named capturing groups. Otherwise, new TypeScript compiler
does not compile the project and shows the following error:
```
...
TimestampedFilenameGenerator.spec.ts:105:23 - error TS1503: Named capturing groups are only available when targeting 'ES2018' or later
const pattern = /^(?<timestamp>\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2})-(?<scriptName>[^.]+?)(?:\.(?<extension>[^.]+))?$/;// timestamp-scriptName.extension
...
```
- Refactor usage of `electron-progressbar` for type safety and
less complexity.
This commit is contained in:
@@ -50,16 +50,33 @@ describe('ApplicationContext', () => {
|
||||
// assert
|
||||
expectEmptyState(sut.state);
|
||||
});
|
||||
it('throws when OS is unknown to application', () => {
|
||||
it('rethrows when application cannot provide collection for supported OS', () => {
|
||||
// arrange
|
||||
const expectedError = 'expected error from application';
|
||||
const applicationStub = new ApplicationStub();
|
||||
const initialOs = OperatingSystem.Android;
|
||||
const targetOs = OperatingSystem.ChromeOS;
|
||||
const context = new ObservableApplicationContextFactory()
|
||||
.withAppContainingCollections(initialOs, targetOs)
|
||||
.withInitialOs(initialOs);
|
||||
// act
|
||||
const sut = context.construct();
|
||||
const { app } = context;
|
||||
app.getCollection = () => { throw new Error(expectedError); };
|
||||
const act = () => sut.changeContext(targetOs);
|
||||
// assert
|
||||
expect(act).to.throw(expectedError);
|
||||
});
|
||||
it('throws when OS state is unknown to application', () => {
|
||||
// arrange
|
||||
const knownOs = OperatingSystem.Android;
|
||||
const unknownOs = OperatingSystem.ChromeOS;
|
||||
const expectedError = `Operating system "${OperatingSystem[unknownOs]}" state is unknown.`;
|
||||
const sut = new ObservableApplicationContextFactory()
|
||||
.withApp(applicationStub)
|
||||
.withAppContainingCollections(knownOs)
|
||||
.withInitialOs(knownOs)
|
||||
.construct();
|
||||
// act
|
||||
applicationStub.getCollection = () => { throw new Error(expectedError); };
|
||||
const act = () => sut.changeContext(OperatingSystem.Android);
|
||||
const act = () => sut.changeContext(unknownOs);
|
||||
// assert
|
||||
expect(act).to.throw(expectedError);
|
||||
});
|
||||
@@ -181,14 +198,28 @@ describe('ApplicationContext', () => {
|
||||
const actual = sut.state.os;
|
||||
expect(actual).to.deep.equal(expected);
|
||||
});
|
||||
it('throws when OS is unknown to application', () => {
|
||||
it('rethrows when application cannot provide collection for supported OS', () => {
|
||||
// arrange
|
||||
const expectedError = 'expected error from application';
|
||||
const applicationStub = new ApplicationStub();
|
||||
applicationStub.getCollection = () => { throw new Error(expectedError); };
|
||||
const knownOperatingSystem = OperatingSystem.macOS;
|
||||
const context = new ObservableApplicationContextFactory()
|
||||
.withAppContainingCollections(knownOperatingSystem)
|
||||
.withInitialOs(knownOperatingSystem);
|
||||
const { app } = context;
|
||||
app.getCollection = () => { throw new Error(expectedError); };
|
||||
// act
|
||||
const act = () => context.construct();
|
||||
// assert
|
||||
expect(act).to.throw(expectedError);
|
||||
});
|
||||
it('throws when OS is not supported', () => {
|
||||
// arrange
|
||||
const unknownInitialOperatingSystem = OperatingSystem.BlackBerry10;
|
||||
const expectedError = `Operating system "${OperatingSystem[unknownInitialOperatingSystem]}" is not supported.`;
|
||||
// act
|
||||
const act = () => new ObservableApplicationContextFactory()
|
||||
.withApp(applicationStub)
|
||||
.withAppContainingCollections(OperatingSystem.Android /* unrelated */)
|
||||
.withInitialOs(unknownInitialOperatingSystem)
|
||||
.construct();
|
||||
// assert
|
||||
expect(act).to.throw(expectedError);
|
||||
@@ -222,24 +253,24 @@ class ObservableApplicationContextFactory {
|
||||
|
||||
private initialOs = ObservableApplicationContextFactory.DefaultOs;
|
||||
|
||||
constructor() {
|
||||
public constructor() {
|
||||
this.withAppContainingCollections(ObservableApplicationContextFactory.DefaultOs);
|
||||
}
|
||||
|
||||
public withAppContainingCollections(
|
||||
...oses: OperatingSystem[]
|
||||
): ObservableApplicationContextFactory {
|
||||
): this {
|
||||
const collectionValues = oses.map((os) => new CategoryCollectionStub().withOs(os));
|
||||
const app = new ApplicationStub().withCollections(...collectionValues);
|
||||
return this.withApp(app);
|
||||
}
|
||||
|
||||
public withApp(app: IApplication): ObservableApplicationContextFactory {
|
||||
public withApp(app: IApplication): this {
|
||||
this.app = app;
|
||||
return this;
|
||||
}
|
||||
|
||||
public withInitialOs(initialOs: OperatingSystem) {
|
||||
public withInitialOs(initialOs: OperatingSystem): this {
|
||||
this.initialOs = initialOs;
|
||||
return this;
|
||||
}
|
||||
@@ -250,6 +281,7 @@ class ObservableApplicationContextFactory {
|
||||
return sut;
|
||||
}
|
||||
}
|
||||
|
||||
function getDuplicates<T>(list: readonly T[]): T[] {
|
||||
return list.filter((item, index) => list.indexOf(item) !== index);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user