TypeScript Version: 3.7.2
Search Terms:
assert function import export
Code
// Module asserts.ts
function isNonNullable<T>(obj: T): asserts obj is NonNullable<T> {
if(obj === undefined || obj === null) {
throw new Error('Must not be a nullable value');
}
}
export {
isNonNullable
};
// Module test.ts
import * as asserts from './asserts.ts';
function test(obj: string | null): void {
asserts.isNonNullable(obj);
obj.trim();
}
Expected behavior:
Everything works as expected
Actual behavior:
Error: Assertions require every name in the call target to be declared with an explicit type annotation.
If I rewrite test.ts with:
// Module test.ts
import { isNonNullable } from './asserts.ts';
function test(obj: string | null): void {
isNonNullable(obj);
obj.trim();
}
then everything compiles without any error
TypeScript Version: 3.7.2
Search Terms:
assert function import export
Code
Expected behavior:
Everything works as expected
Actual behavior:
Error: Assertions require every name in the call target to be declared with an explicit type annotation.
If I rewrite test.ts with:
then everything compiles without any error