Skip to content

In JS, assertions imported via commonjs have bogus error #38379

Closed
@sandersn

Description

@sandersn

Code

// @filename: declares.d.ts
// this is the declaration for 'assert' from @types/node
export function art(value: any, message?: string | Error): asserts value;

// @filename: test.js
const { art } = require('./declares')
let x = 1
art(x)

Expected behavior:
No error.

Actual behavior:
Error: "Assertions require every name in the call target to be declared with an explicit type annotation."

There is no error when using ES imports:

// @filename: test2.js
import { art } from './declares'
let x = 1
art(x)

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions