fix(developer): better types in model-info-compiler.ts

This commit is contained in:
Eddie Antonio Santos 2019-11-27 21:22:31 -07:00
parent eb2ee8d14f
commit a4c094cd21
No known key found for this signature in database
GPG key ID: DD411EA4D9509D87

View file

@ -69,12 +69,15 @@ export function writeMergedModelMetadataFile(
// https://help.keyman.com/developer/cloud/model_info/1.0
//
function setModelMetadata(field: string, expected: any, warn: boolean = true) {
if(model_info[field] && model_info[field] !== expected) {
if(warn || typeof warn === 'undefined')
function setModelMetadata(field: keyof ModelInfoFile, expected: unknown, warn: boolean = true) {
if (model_info[field] && model_info[field] !== expected) {
if (warn || typeof warn === 'undefined')
console.warn(`Warning: source ${sourceModelInfoFileName} field ${field} value "${model_info[field]}" does not match "${expected}" found in source file metadata.`);
}
model_info[field] = model_info[field] || expected;
// TypeScript gets upset with this assignment, because it cannot deduce
// the exact type of model_info[field] -- there are many possibilities!
// So we assert that it's unknown so that TypeScript can chill.
(<unknown> model_info[field]) = model_info[field] || expected;
}
//