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.
Sorry for not going deeper in the topic of the particular assert
you use, it seems it is node native, which is different than those supported by TypeScript
But nevertheless, this can be a good hint:
// This is necessary to avoid the error: `Assertions require every name in the call target to be declared with an explicit type annotation.ts(2775)`
// `assertion.ts(16, 14): 'assert' needs an explicit type annotation.`
// https://github.com/microsoft/TypeScript/issues/36931#issuecomment-846131999
type Assert = (condition: unknown, message?: string) => asserts condition;
export const assert: Assert = (condition: unknown, msg?: string): asserts condition => {
if (!condition) {
throw new AssertionError(msg);
}
};
And this is how you would use it:
assert(pathStr || pathParts, "Either `pathStr` or `pathParts` should be defined");