Microsoft/TypeScript

importing merged declorations in js files

Open

#61997 opened on Jul 5, 2025

View on GitHub
 (0 comments) (0 reactions) (0 assignees)TypeScript (48,455 stars) (6,726 forks)batch import
BugDomain: JSDocHelp Wanted

Description

🔎 Search Terms

is a type and cannot be imported in JavaScript files; JSDoc; Import; Declaration Merging.

🕗 Version & Regression Information

  • This is the behavior in every version I tried (v5.8.3 - Nightly)

💻 Code

// @filename: foo.impl.js
/**
 * @import { Foo } from "./foo.js"
 */

/**
 * @returns { Foo } 
 */
export function alloc() {
    return {
        prop1: 42,
        prop2: "lorem ipsum"
    }
}

// @filename: foo.js
export * as Foo from "./foo.impl.js"
/**
 * @typedef Foo
 * @prop { number } prop1
 * @prop { string } prop2
 */

// @filename: index.js
import { Foo } from "./foo.js"
//       ^^^ 'Foo' is a type and cannot be imported in JavaScript files. Use 'import("./foo.js").Foo' in a JSDoc type annotation.ts(18042)

const foo = Foo.alloc();

🙁 Actual behavior

tsc/lsp emmits error

🙂 Expected behavior

no error

Additional information about the issue

same example works fine using ts files

Contributor guide