Microsoft/TypeScript

importing merged declorations in js files

Open

#61 997 ouverte le 5 juil. 2025

Voir sur GitHub
 (0 commentaires) (0 réactions) (0 assignés)TypeScript (6 726 forks)batch import
BugDomain: JSDocHelp Wanted

Métriques du dépôt

Stars
 (48 455 stars)
Métriques de merge PR
 (Merge moyen 6j 17h) (9 PRs mergées en 30 j)

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

Guide contributeur