judge: fix type check

This commit is contained in:
panda committed 2022-06-27 16:52:55 +08:00
1 parent 0195ba361e
commit 00bdea78d2
1 file changed
+3 -3
+3 -3
View File
@@ -13,9 +13,9 @@ export async function judge({
: ('content' in code) : ('content' in code)
? code.content.toString().replace(/\r/g, '') ? code.content.toString().replace(/\r/g, '')
: ''; : '';
let answers; let answers: { [x: string]: string | string[] } = {};
try { try {
answers = yaml.load(answer); answers = yaml.load(answer) as { [x: string]: string | string[] };
assert(typeof answers === 'object'); assert(typeof answers === 'object');
} catch (e) { } catch (e) {
return end({ return end({
@@ -39,7 +39,7 @@ export async function judge({
memory: 0, memory: 0,
}; };
if (typeof ansInfo[0] === 'string') { if (typeof ansInfo[0] === 'string') {
if (ansInfo[0].trim() === answers[key].trim()) { if (ansInfo[0].trim() === (answers[key] as string).trim()) {
totalScore += score; totalScore += score;
totalStatus = Math.max(totalStatus, STATUS.STATUS_ACCEPTED); totalStatus = Math.max(totalStatus, STATUS.STATUS_ACCEPTED);
next({ next({