mirror of
https://github.com/thelounge/thelounge
synced 2024-11-22 20:13:07 +00:00
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:
parent
1597c2c56e
commit
fd14b4a172
1 changed files with 5 additions and 7 deletions
|
@ -421,8 +421,10 @@ function indexRequest(req: Request, res: Response) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
||||||
const config = getServerConfiguration() as IndexTemplateConfiguration;
|
const config: IndexTemplateConfiguration = {
|
||||||
config.cacheBust = Helper.getVersionCacheBust();
|
...getServerConfiguration(),
|
||||||
|
...{cacheBust: Helper.getVersionCacheBust()},
|
||||||
|
};
|
||||||
|
|
||||||
res.send(_.template(file)(config));
|
res.send(_.template(file)(config));
|
||||||
}
|
}
|
||||||
|
@ -901,11 +903,7 @@ function getClientConfiguration(): ClientConfiguration {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getServerConfiguration(): ServerConfiguration {
|
function getServerConfiguration(): ServerConfiguration {
|
||||||
const config = _.clone(Config.values) as ServerConfiguration;
|
return {...Config.values, ...{stylesheets: packages.getStylesheets()}};
|
||||||
|
|
||||||
config.stylesheets = packages.getStylesheets();
|
|
||||||
|
|
||||||
return config;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function performAuthentication(this: Socket, data) {
|
function performAuthentication(this: Socket, data) {
|
||||||
|
|
Loading…
Reference in a new issue