Microsoft/TypeScript

importing merged declorations in js files

Open

#61.997 aperta il 5 lug 2025

Vedi su GitHub
 (0 commenti) (0 reazioni) (0 assegnatari)TypeScript (6726 fork)batch import
BugDomain: JSDocHelp Wanted

Metriche repository

Star
 (48.455 star)
Metriche merge PR
 (Merge medio 6g 17h) (9 PR mergiate in 30 g)

Descrizione

🔎 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

Guida contributor