-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue
Milestone
Description
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
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue