Skip to content

Commit

Permalink
Fix TS2571 errors in BotBuilder-bf-generate-JS (#3472)
Browse files Browse the repository at this point in the history
* Fix npm run test error TS2345 for generator

* Revert "Fix npm run test error TS2345 for generator"

This reverts commit e49afb6.

* Try fixing catch var error TS2571

* Fix catch var error TS2571 2

* Fix error TS2345

* Fix more error TS2571: Object is of type 'unknown'.

* Fix test/generate.test.ts(326,36): error TS2571

* Fix more error TS2571

* Fix test/swagger.test.ts: error TS2571
  • Loading branch information
BruceHaley committed Sep 9, 2021
1 parent 9d5676e commit ea8d1f2
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 38 deletions.
Expand Up @@ -60,7 +60,7 @@ export default class GenerateDialog extends Command {
feedback})
return true
} catch (e) {
this.thrownError(e)
this.thrownError(e as Error)
}
}

Expand Down
Expand Up @@ -40,7 +40,7 @@ export default class Swagger extends Command {
this.progress(`Schema: ${schemaPath}`)
return true
} catch (e) {
this.thrownError(e)
this.thrownError(e as Error)
}
}

Expand Down
Expand Up @@ -155,12 +155,12 @@ export async function writeFile(path: string, val: string, feedback: Feedback, s
}
await fs.writeFile(path, val)
} catch (e) {
const match = /position ([0-9]+)/.exec(e.message)
const match = /position ([0-9]+)/.exec((e as Error).message)
if (match) {
const offset = Number(match[1])
val = `${val.substring(0, offset)}^^^${val.substring(offset)}`
}
feedback(FeedbackType.error, `${e.message}${os.EOL}${val}`)
feedback(FeedbackType.error, `${(e as Error).message}${os.EOL}${val}`)
}
}

Expand Down Expand Up @@ -448,7 +448,7 @@ async function processTemplate(
try {
filename = lgTemplate.evaluate('filename', scope) as string
} catch (e) {
throw new Error(`${templateName}: ${e.message}`)
throw new Error(`${templateName}: ${(e as Error).message}`)
}
} else {
// Infer name
Expand Down Expand Up @@ -550,7 +550,7 @@ async function processTemplate(
}
}
} catch (e) {
feedback(FeedbackType.error, e.message)
feedback(FeedbackType.error, (e as Error).message)
} finally {
process.chdir(oldDir)
}
Expand Down Expand Up @@ -785,7 +785,7 @@ async function ensureEntitiesAndTemplates(
}
}
} catch (e) {
feedback(FeedbackType.error, e.message)
feedback(FeedbackType.error, (e as Error).message)
}
}
}
Expand Down Expand Up @@ -856,7 +856,7 @@ function expandSchema(schema: any, scope: any, path: string, inProperties: boole
}
} catch (e) {
if (missingIsError) {
feedback(FeedbackType.error, e.message)
feedback(FeedbackType.error, (e as Error).message)
}
}
}
Expand Down Expand Up @@ -1188,7 +1188,7 @@ export async function generate(
await fs.copyFile(schemaPath, outSchemaPath)
}
} catch (e) {
feedback(FeedbackType.error, e.message)
feedback(FeedbackType.error, (e as Error).message)
}

const end = process.hrtime.bigint()
Expand Down Expand Up @@ -1233,4 +1233,4 @@ export async function expandPropertyDefinition(property: string, schema: any, te
}
}
return schema
}
}
Expand Up @@ -171,7 +171,7 @@ export async function mergeAssets(schemaName: string, oldPath: string, newPath:
await mergeOtherFiles(oldPath, oldFileList, newPath, newFileList, mergedPath, feedback)
}
} catch (e) {
feedback(FeedbackType.error, e.message)
feedback(FeedbackType.error, (e as Error).message)
}

return true
Expand Down Expand Up @@ -804,4 +804,4 @@ async function getSynonyms(schemaName: string, newPath: string, locale: string):
}

return propertyValueSynonyms
}
}
Expand Up @@ -163,7 +163,7 @@ describe('dialog:generate library', async () => {
assert.ok(await generateTest('test/transcripts/sandwich.transcript', 'sandwich', output, false), 'Could not generate test script')
await compareToOracle(ppath.join(tempDir, 'sandwich.test.dialog'))
} catch (e) {
assert.fail(e.message)
assert.fail((e as Error).message)
}
})

Expand All @@ -173,7 +173,7 @@ describe('dialog:generate library', async () => {
assert.ok(await generateTest('test/transcripts/addItemWithButton.transcript', 'msmeeting-actions', output, false), 'Could not generate test script')
await compareToOracle(ppath.join(tempDir, 'addItemWithButton.test.dialog'))
} catch (e) {
assert.fail(e.message)
assert.fail((e as Error).message)
}
})

Expand Down Expand Up @@ -229,7 +229,7 @@ describe('dialog:generate library', async () => {
const dialog = await fs.readFile(ppath.join(output, 'dialogs/Bread/sandwich-Bread-missing.dialog'))
assert.ok(!dialog.toString().includes('priority'), 'Did not override top-level file')
} catch (e) {
assert.fail(e.message)
assert.fail((e as Error).message)
}
})

Expand All @@ -244,7 +244,7 @@ describe('dialog:generate library', async () => {
assert.ok(!await fs.pathExists(ppath.join(output, 'dialogs/Bread')), 'Generated non-singleton directories')
assert.ok(await fs.pathExists(ppath.join(output, 'sandwich.dialog')), 'Did not generate root dialog')
} catch (e) {
assert.fail(e.message)
assert.fail((e as Error).message)
}
})

Expand All @@ -264,7 +264,7 @@ describe('dialog:generate library', async () => {
await checkDirectory(ppath.join(output, 'language-understanding', 'en-us'), 2, 10)
await checkPattern(ppath.join(output, '**'), 134)
} catch (e) {
assert.fail(e.message)
assert.fail((e as Error).message)
}
})

Expand Down Expand Up @@ -313,7 +313,7 @@ describe('dialog:generate library', async () => {
}
}
} catch (e) {
assert.fail(e.message)
assert.fail((e as Error).message)
}

try {
Expand All @@ -323,7 +323,7 @@ describe('dialog:generate library', async () => {
result = await LuisBuilder.build(luFiles, true, 'en-us', undefined)
result.validate()
} catch (e) {
assert.fail(`${e.source}: ${e.message}`)
assert.fail(`${description}: ${(e as Error).message}`)
}

try {
Expand All @@ -343,7 +343,7 @@ describe('dialog:generate library', async () => {
resourceExplorer.addFolder(`${testOutput}`, true, false)
resourceExplorer.loadType(`unittest_${prefix}.dialog`)
} catch (e) {
assert.fail(e.message)
assert.fail((e as Error).message)
}
} else {
assert.fail('Did not generate')
Expand All @@ -356,7 +356,7 @@ describe('dialog:generate library', async () => {
await ft.Schema.readSchema(notObject)
assert.fail('Did not detect bad schema')
} catch (e) {
assert(e.message.includes('must be of type object'), 'Missing type object')
assert((e as Error).message.includes('must be of type object'), 'Missing type object')
}
})

Expand All @@ -365,7 +365,7 @@ describe('dialog:generate library', async () => {
await ft.Schema.readSchema(badSchema)
assert.fail('Did not detect bad schema')
} catch (e) {
assert(e.message.includes('is not a valid JSON Schema'), 'Missing valid JSON schema')
assert((e as Error).message.includes('is not a valid JSON Schema'), 'Missing valid JSON schema')
}
})

Expand All @@ -390,7 +390,7 @@ describe('dialog:generate library', async () => {
assert.strictEqual(global, globalExpected, `Expected ${globalExpected} global schemas and found ${global}`)
assert.strictEqual(property, propertyExpected, `Expected ${propertyExpected} property schemas and found ${property}`)
} catch (e) {
assert.fail(e.message)
assert.fail((e as Error).message)
}
})

Expand All @@ -403,7 +403,7 @@ describe('dialog:generate library', async () => {
assert(expansion.$entities, 'Did not generate $entities')
assert.strictEqual(expansion.$entities.length, 1, 'Wrong number of entities')
} catch (e) {
assert.fail(e.message)
assert.fail((e as Error).message)
}
})

Expand All @@ -420,7 +420,7 @@ describe('dialog:generate library', async () => {
})), 'Should have failed generation')
assert.strictEqual(errors, 4, 'Wrong number of errors')
} catch (e) {
assert.fail(e.message)
assert.fail((e as Error).message)
}
})

Expand All @@ -446,7 +446,7 @@ describe('dialog:generate library', async () => {
await includes(`${testOutput}/language-understanding/en-us/examples/enum-examples-examplesValue.en-us.lu`, 'why not')
await includes(`${testOutput}/language-understanding/en-us/examplesArray/enum-examplesArray-examplesArrayValue.en-us.lu`, 'repent again')
} catch (e) {
assert.fail(e.message)
assert.fail((e as Error).message)
}
})

Expand Down Expand Up @@ -474,7 +474,7 @@ describe('dialog:generate library', async () => {
assert.strictEqual(errors, 2, 'Wrong number of errors')
assert.strictEqual(warnings, 0, 'Wrong number of warnings')
} catch (e) {
assert.fail(e.message)
assert.fail((e as Error).message)
}
})

Expand All @@ -498,7 +498,7 @@ describe('dialog:generate library', async () => {
assert.strictEqual(warnings, 3, 'Wrong number of warnings')
await compareToOracle(ppath.join(tempDir, 'unittest_transforms.dialog'))
} catch (e) {
assert.fail(e.message)
assert.fail((e as Error).message)
}
})

Expand Down
Expand Up @@ -226,7 +226,7 @@ function beforeSetup(singleton: boolean) {
feedback: errorOnly
})
} catch (e) {
assert.fail(e.message)
assert.fail((e as Error).message)
}
}
}
Expand All @@ -238,7 +238,7 @@ function beforeEachSetup() {
await fs.remove(mergedDir)
await fs.copy(originalDir, mergedDir)
} catch (e) {
assert.fail(e.message)
assert.fail((e as Error).message)
}
}
}
Expand All @@ -262,7 +262,7 @@ describe('dialog:generate --merge files', async function () {
assertCompare(comparison, errors, comparison.originalFiles.length)
assertCheck(comparison, errors)
} catch (e) {
assert.fail(e.message)
assert.fail((e as Error).message)
}
})

Expand Down Expand Up @@ -292,7 +292,7 @@ describe('dialog:generate --merge files', async function () {
await assertUnchanged('language-generation/en-us/Name/sandwichMerge-Name.en-us.lg', true, errors)
assertCheck(comparison, errors)
} catch (e) {
assert.fail(e.message)
assert.fail((e as Error).message)
}
})

Expand Down Expand Up @@ -349,7 +349,7 @@ describe('dialog:generate --merge files', async function () {

assertCheck(comparison, errors)
} catch (e) {
assert.fail(e.message)
assert.fail((e as Error).message)
}
})
})
Expand All @@ -374,7 +374,7 @@ describe('dialog:generate --merge singleton', async function () {
assertCompare(comparison, errors, comparison.originalFiles.length)
assertCheck(comparison, errors)
} catch (e) {
assert.fail(e.message)
assert.fail((e as Error).message)
}
})

Expand Down Expand Up @@ -406,7 +406,7 @@ describe('dialog:generate --merge singleton', async function () {

await compareToOracle(ppath.join(mergedDir, 'sandwichMerge.dialog'))
} catch (e) {
assert.fail(e.message)
assert.fail((e as Error).message)
}
})

Expand Down Expand Up @@ -466,7 +466,7 @@ describe('dialog:generate --merge singleton', async function () {
assert.deepStrictEqual(mergedDialog.triggers[2], newTrigger, 'Did not preserve custom trigger')
assert.deepStrictEqual(mergedDialog.triggers[3], reorderedTrigger, 'Did not preserve reordered trigger')
} catch (e) {
assert.fail(e.message)
assert.fail((e as Error).message)
}
})
})
Expand Up @@ -37,7 +37,7 @@ describe('dialog:generate:swagger', async () => {
let schemaFile = await fs.readFile(ppath.join(output, schemaName))
assert.ok(schemaFile.toString().includes('$parameters'), 'Did not generate parameters')
} catch (e) {
assert.fail(e.message)
assert.fail((e as Error).message)
}
})

Expand All @@ -51,7 +51,7 @@ describe('dialog:generate:swagger', async () => {
})
assert.ok(await fs.pathExists(ppath.join(outDir, 'dialogs', 'form', 'petOrder-form-HttpRequestIntent.dialog')), 'Did not generate http request dialog')
} catch (e) {
assert.fail(e.message)
assert.fail((e as Error).message)
}
})

Expand Down

0 comments on commit ea8d1f2

Please sign in to comment.