Table of Contents
Issue
I have the JavaScript code below, and I’m using the TypeScript Compiler (TSC) to provide type-checking as per the Typescript Docs JSDoc Reference.
const assert = require('assert');
const mocha = require('mocha');
mocha.describe('Array', () => {
mocha.describe('#indexOf()', () => {
mocha.it('should return -1 when the value is not present',
/** */
() => {
assert.strictEqual([1, 2, 3].indexOf(4), -1);
});
});
});
I’m seeing this error:
Assertions require every name in the call target to be declared with an explicit type annotation.ts(2775)
SomeFile.test.js(2, 7): 'assert' needs an explicit type annotation.
How can I resolve this error?
Solution
You need to add a JSDoc type annotation for your assert
variable such as in the example below. You can add a more specific type than {any}
if you like.
/** @type {any} */
const assert = require('assert');
See this Github issue for more info.
Answered By – derekbaker783
Answer Checked By – Willingham (BugsFixing Volunteer)