microsoft / microsoft/TypeScript

importing merged declorations in js files

Open
#61,997 0 comments 0 reactions 0 assignees View on GitHub
Bug Domain: JSDoc Help Wanted
Dominant language
Go
Stars
111k
Forks
14.3k
PR merge metrics
PR metrics pending

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

```ts
// @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

Open the contributing guide

Research direction

Reproduce the example using foo.impl.js, foo.js, and index.js with tsc or the language service, then trace the diagnostic for the import of Foo and compare it with the working TypeScript-file case. Done means the JavaScript example reports no import error and Foo.alloc() remains usable.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.