Microsoft/TypeScript

importing merged declorations in js files

Open

#61,997 创建于 2025年7月5日

在 GitHub 查看
 (0 评论) (0 反应) (0 负责人)TypeScript (6,726 fork)batch import
BugDomain: JSDocHelp Wanted

仓库指标

Star
 (48,455 star)
PR 合并指标
 (平均合并 6天 17小时) (30 天内合并 9 个 PR)

描述

🔎 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

贡献者指南