make getClientConfiguration type safe

TS type assertions need to be avoided.

The following trivial example demonstrates why

```
type Person = {
	name: string;
	isBad: boolean;
};

function makePerson(): Person {
	const p: Person = {name: 'whatever'} as Person
	p.isBad = false
	return p // theoretically we are now good, p is a Person
}
```

Should the type ever change though, TS will happily trot along

```
type Person = {
	name: string;
	isBad: boolean;
	omgHowCouldYou: number;
};

function makePerson(): Person {
	const p: Person = {name: 'whatever'} as Person
	p.isBad = true
	return p // p is *not* a Person, omgHowCouldYou is missing
}
```

But we pinky swore to the compiler that p is in fact a Person.
In other words, the types are now wrong and you will fail during
runtime.
This commit is contained in:
Reto Brunner 2022-11-22 03:07:29 +01:00
parent 1597c2c56e
commit fd14b4a172

View file

@ -421,8 +421,10 @@ function indexRequest(req: Request, res: Response) {
throw err;
}
const config = getServerConfiguration() as IndexTemplateConfiguration;
config.cacheBust = Helper.getVersionCacheBust();
const config: IndexTemplateConfiguration = {
...getServerConfiguration(),
...{cacheBust: Helper.getVersionCacheBust()},
};
res.send(_.template(file)(config));
}
@ -901,11 +903,7 @@ function getClientConfiguration(): ClientConfiguration {
}
function getServerConfiguration(): ServerConfiguration {
const config = _.clone(Config.values) as ServerConfiguration;
config.stylesheets = packages.getStylesheets();
return config;
return {...Config.values, ...{stylesheets: packages.getStylesheets()}};
}
function performAuthentication(this: Socket, data) {